Browsing 7239 questions and answers with Jon Skeet
Hi my code works when tested with ArrayLists that contain objects but puts out the error java.lang.IndexOutOfBoundsException: Index: 0, Size: 0 when the arrayList is empty. What am I getting wrong. ArrayList.get() is behaving exactly... more 10/10/2013 9:15:58 PM
You're trying to select roleName twice - you've already done the right thing by selecting it the first time. You're also overwriting the roleName field/property in the model multiple times, whereas presumably you want to retain all the... more 10/10/2013 12:37:22 PM
What I get is a different number every time, as if the keyword volatile were not used. Is it the right behaviour of the keyword? Specifying the variable as volatile doesn't make either the increment or decrement operation atomic.... more 10/10/2013 11:28:49 AM
One simple option which does introduce an extra hop (but would probably have negligible performance impact) would be to just use a lambda expression: Action<IApplicationState, T> action = (state, value) => state.Foo =... more 10/10/2013 10:01:03 AM
BinaryFormatter.AssemblyFormat is documented as: Gets or sets the behavior of the deserializer with regards to finding and loading assemblies. There's no indication that it has an impact on the serializing path. Personally I would... more 10/10/2013 7:49:13 AM
If you want the result to potentially be null, then you shouldn't be calling Convert.ToDecimal - which always returns decimal. Instead, you should use: x = obj.sal == null ? (decimal?) null :... more 10/10/2013 7:19:19 AM
Well yes, the problem is here: while (true) { return i; } The method is declared to return boolean, but i is declared as an int. That's not going to work. You need to either change the return type to int, or work out when you want... more 10/10/2013 5:43:20 AM
The conditional operator makes each set of choices simple - and if you lay it out correctly, it's really easy to read, once you've got the hang of the pattern: return x ? subMethod1(o) : y ? subMethod2(o) : z ? subMethod3(o) ... more 10/9/2013 8:09:20 PM
I will have to think of the leap year and also which month has 31 days and which doesn't. You shouldn't need to write any code for yourself which does that. You can either use the existing DateTime type, or potentially use my Noda... more 10/9/2013 3:42:05 PM
It sounds like you're looking for Class.getInterfaces(): public static void showInterfaces(Object obj) { for (Class<?> iface : obj.getClass().getInterfaces()) { System.out.println(iface.getName()); } } For example,... more 10/9/2013 3:28:25 PM