Browsing 7239 questions and answers with Jon Skeet

Is there anyway to override methods when using templates?

I need to have the same method but having different argument types : public interface IKid<T,D,S> { public T findCookie(D id); public T findCookie(S id); ...
Jon Skeet
people
quotationmark

Is there anyway to avoid this problem? You just need to provide different names for the methods - it's as simple as that. Aside from anything else, that removes the obvious problem if you implement IKid<Object, String, String>... more 6/4/2014 10:48:54 AM

people

how to sort date in descending order using comparator

I have a bean object testBean with getter setter and methods.I am retrieving the results from the database and storing it in a TreeMap The Output of the Map will look like...
Jon Skeet
people
quotationmark

But i couldn't able to sort the date in descending order. Two easy options: You could just reverse your comparison yourself, using secondDate.compareTo(firstDate). (I assume that in your real code you're actually returning retVal;... more 6/4/2014 9:56:25 AM

people

How can I create a new instance of ImmutableDictionary?

I would like to write something like this: var d = new ImmutableDictionary<string, int> { { "a", 1 }, { "b", 2 } }; (using ImmutableDictionary from...
Jon Skeet
people
quotationmark

Either create a "normal" dictionary first and call ToImmutableDictionary (as per your own answer), or use ImmutableDictionary<,>.Builder: var builder = ImmutableDictionary.CreateBuilder<string, int>(); builder.Add("a",... more 6/4/2014 9:29:15 AM

people

Compare two object lists with LINQ on specific property

I have these two lists (where the Value in a SelectListItem is a bookingid): List<SelectListItem> selectedbookings; List<Booking> availableBookings; I need to find...
Jon Skeet
people
quotationmark

I need to find the ids from selectedBookings that are not in availableBookings. That's easy - it's all the IDs in selected bookings except those that are in available bookings: var ids = selectedBookings.Select(x =>... more 6/4/2014 9:15:53 AM

people

what the java command's jar option really does

Does the -jar option of the java command also compile the sources before running the main method? I believe so but i would like to have a better understanding of the internal...
Jon Skeet
people
quotationmark

Does the -jar option of the java command also compile the sources before running the main method? No, absolutely not. It just specifies the jar file in which to find the manifest specifying the main class, and (usually) the class file... more 6/4/2014 9:05:57 AM

people

why array is not sorted in below javacode?

when i run the code ,array p is not sorted. I cant figure out why is this happening? import java.util.Arrays; public class Main { public static void main (String[]...
Jon Skeet
people
quotationmark

You're specifically asking to sort the portion from p[5] to p[9] exclusive of the upper bound... so 4 elements, which are already in order (1, 4, 5, 6). If you want to sort to p[9] inclusive, you should call Arrays.sort(p, 5, 10); From... more 6/4/2014 8:41:13 AM

people

Easymock mocks object method invocation with another method invocation as an argument

How to properly record mocks method when as an argument I put a result of another method of the same mock: mockObj.doSth(arg1, arg2, mockObj.doSthElse(), arg2); I'm testing a...
Jon Skeet
people
quotationmark

You need to think of it as: int tmp = mockObj.doSthElse(); mockObj.doSth(arg1, arg2, tmp, arg3); So you set up the expectation (and return value) for doSthElse, then you expect that value as the argument for doSth. I can't explain why... more 6/4/2014 8:17:38 AM

people

Run time errors in eclipse android application [unfortunately application has stopped]

I am facing an issue in my app ,when I click the button inside my app it gives the error (unfortunately application has stopped), and these are problems in Logcat : please...
Jon Skeet
people
quotationmark

It looks like you're trying to parse a value starting "android.widget.EditText" - which suggests you may have code like this: int x = Integer.parseInt(editText.toString()); That's not going to get the text of the EditText - for that,... more 6/4/2014 6:07:08 AM

people

When checking for a instance of the current class, why doesn't "x instanceof getClass()" work?

I have an abstract class AssociativeFunction which extends Expr. There are different functions which are subclasses of AssociativeFunction, and there are other expressions which...
Jon Skeet
people
quotationmark

Why does the following not work? Because instanceof requires a type name as the second operand at compile-time, basically. You won't be able to use the instanceof operator. The production for the instanceof operator is: ... more 6/3/2014 8:19:06 PM

people

How to neatly query corresponding object array items?

I have an array of objects that'll be used for some process. var x = new List<MyObject>() { new MyObject(), new MyObject(), ... }.ToArray(); After the process, it returns...
Jon Skeet
people
quotationmark

Well, you can use Zip to pair them up: var pairs = x.Zip(y, (a, b) => new { a, b }) .Where(pair => !pair.b.IsOkay) .ToArray(); You can change the delegate passed to Zip to compose the two values... more 6/3/2014 7:09:55 PM

people