Browsing 7239 questions and answers with Jon Skeet

JodaTime Interval irrespective of the year?

I'd like to have a JodaTime Interval which represents a range of days within a year. For example, January 21 - February 23 or the like, or even December 7 - January 13. Now I'd...
Jon Skeet
people
quotationmark

I don't believe there's any such type within Joda Time - and Interval deals with instants, where it sounds like you're interested in day/month values anyway. You should probably construct your own type that is composed of two MonthDay... more 10/15/2014 4:29:19 PM

people

How to iterate over a hashmap which has object as keys and set<objects> as values and print both?

I have a hashmap which take the object Node as a key and set of Nodes as values. Nodes are just an object with an integer value. The values are just what they are connected to in...
Jon Skeet
people
quotationmark

Well you just need a different way of converting a Set<Node> to a String. Currently you're using the default toString() implementation, but it's easy to write your own, e.g. private static String commaSeparate(Iterable<?>... more 10/15/2014 4:21:50 PM

people

java.lang.IllegalMonitorStateException trhown when calling signal()

i' m working in a multithreading program. The threads are working in a matrix (workerThread) and i have got a thread (display) that print the matrix state.i' m getting this...
Jon Skeet
people
quotationmark

Yes, the problem is that in increaseRow you're calling monitor.signal() without having locked lock first. From the documentation for Condition.signal(): An implementation may (and typically does) require that the current thread hold... more 10/15/2014 1:54:54 PM

people

using reflection to get properties of class inheriting an interface

I have the following scenario where I would like to get the properties of a class which implements an interface, however excluding those properties which are virtual. Just to make...
Jon Skeet
people
quotationmark

I suspect you want IsFinal: To determine if a method is overridable, it is not sufficient to check that IsVirtual is true. For a method to be overridable, IsVirtual must be true and IsFinal must be false. For example, a method might be... more 10/15/2014 1:18:03 PM

people

How can I get elements of a certain name from an XML document as an XML String? (with XDocument)

How can I get elements of a certain name from an XML document as an XML String? (with XDocument) I.e, say I have this: <root> <orange...
Jon Skeet
people
quotationmark

The problem is that you're calling ToString() on the result of calling Descendants(). It's not really clear what you expected that to do, but you are getting the elements correctly. For example: using (TextReader reader =... more 10/15/2014 10:39:05 AM

people

Should I Allow Asymmetric Equals?

I have a C# type for which it makes logical sense to compare for equality with int. Call this type Number. However, I can't make Equals symmetric, because I can't change...
Jon Skeet
people
quotationmark

No. It violates the contract of Object.Equals: The following statements must be true for all implementations of the Equals(Object) method. In the list, x, y, and z represent object references that are not null. ... ... more 10/15/2014 8:49:52 AM

people

java cannot handle a 32 bit number

I am trying to assign 4294967295 to a long. That is (2^32-1) java(netbeans) gives the following error message "integer number too large" in fact I tried to figure out the largest...
Jon Skeet
people
quotationmark

The problem is that you're using 4294967295 as an int literal - but it's not a valid int value. You want it to be a long literal, so you need to put the L suffix on it. This is fine: long x = 4294967295L; From JLS section 3.10.1: An... more 10/15/2014 7:17:46 AM

people

iOS app development in visual studio 2013

Is it possible that ,without using a Mac OS X and XCode, one can create apps for iOS using Visual Studio 2013 on a Windows 7 system ? If yes, then is Swift or Coca Touch available...
Jon Skeet
people
quotationmark

You can sort of do this with Xamarin, as well as building Android applications. You still need to have a Mac in order to build iOS/Mac OS X applications, but you don't need to interact with it directly - it just needs to be on the network... more 10/15/2014 6:29:04 AM

people

Async / Await Guidance: Intrinsic Signature Proliferation

Consider the following class responsible for communicating with an API using the .NET HttpClient. public class ApiServiceAgent { public async Task<string> GetItem() ...
Jon Skeet
people
quotationmark

I'd argue that those methods are asynchronous - but only by virtue of the API part. That asynchrony just propagates its way up. Your second implementation of Repository.GetItem() is problematic, IMO: You should not call an awaiter's... more 10/15/2014 6:06:12 AM

people

pass by value for array in java

I have a code as follows public static int mat(final int a[]) { for(int i=0;i<a.length;i++) a[i]=a[i]+10; System.out.println("Mat Function"); for(int...
Jon Skeet
people
quotationmark

You never pass an array object at all. You pass an array reference, which is always going to be passed by value. If you want to create a copy of the array, then pass a reference to that copy to the method, the simplest approach is... more 10/15/2014 5:49:56 AM

people