Browsing 7239 questions and answers with Jon Skeet

Are Java Generics an All or Nothing Decision?

I have the following code: public class Main { public static void main(String[] args) { Generic generic = new Generic<Integer>(5); List<String>...
Jon Skeet
people
quotationmark

When you use the erasure of a type, it removes all trace of generics - not just the uses of the type parameter T. So your generic variable acts as if it's referring to this type: // After type erasure public class Generic { private... more 10/24/2014 4:17:09 PM

people

NodaTime: Replicating DateTime.Today

My service requests data from an external service that needs an argument for a particular date (doesn't need time information). Until now, I've been using DateTime.Today (e.g....
Jon Skeet
people
quotationmark

To represent a date, you should use LocalDate rather than DateTime, ideally. So you want: var localNow = clock.Now.InZone(serverZone); var today = localNow.Date; If you must use DateTime, then your current code is fine. In Noda Time... more 10/24/2014 3:05:01 PM

people

Why values of array are null in this case?

I am dynamically creating SQL and setting values into them as shown public static void main(String args[]) { try { String vendor_brand_id = "3000"; ...
Jon Skeet
people
quotationmark

Well, you're only populating fixedValues with as many values as are in inputStr: for(int j=0;j<inputStr.length;j++) { fixedvalues[j]=inputStr[j]; System.out.println("jii"+fixedvalues[j]); } You're then running over all 10... more 10/24/2014 2:59:05 PM

people

private method issue c# (change color from tool strip menu item)

I have a logic issue on a tic tac toe game. I want to add a new feature. When I click on "Yellow Color" in the menu, I want my red cross to become yellow when the cursor enters...
Jon Skeet
people
quotationmark

You've declared a local variable in the button_enter method. That variable is only available within the method. If you want that variable to be part of the start of the instance, you need to make it an instance variable, declared outside... more 10/24/2014 1:54:26 PM

people

Thread.Sleep freeze the UI

I know, it's been here many times, but I still don't know how to do it. I want to create a program that will repeatedly download data from database, so the user will see the data...
Jon Skeet
people
quotationmark

To do something periodically, you should use a timer. If you want a timer which fires on the WPF UI thread, use DispatcherTimer - although the fact that you're downloading data suggests that you should either be doing that asynchronously,... more 10/24/2014 7:50:36 AM

people

Date conversion from string to NSDate in ios

I have searched over internet for a long time to get this but I can't find the solution. I have received a date string from web services as "22 May 2014", I have to convert into...
Jon Skeet
people
quotationmark

You're using YYYY, which doesn't mean what you think it means. From the TR35-31 documentation, Y is the symbol for "year in week-of-year calendars". You want dd MMMM yyyy instead as your format string. Mixing week-of-year-based fields and... more 10/24/2014 7:22:24 AM

people

Android Runnable working only once

I am trying to rotate my image. I wrote my function to check rotate speed in the image. In the logic everything is ok but I am using runnable and the setrotate method is working...
Jon Skeet
people
quotationmark

Your loop is just a tight loop - you're executing all the iterations in one go, basically, calling setRotation lots of times. I strongly suspect that all the calls to setRotation are being made... but you're not seeing anything but the... more 10/24/2014 6:20:38 AM

people

Why no promotion when adding ints to List<Double>

in Java I created an ArrayList of Double and I invoked the method list.add(1), however, I get an error. If I can assign an int to a double variable like this: double num = 1; ...
Jon Skeet
people
quotationmark

You're not trying to convert int to double; you're trying to convert int to Double, which is a combination of boxing and the implicit conversion from int to double. That doesn't work, even in a simple assignment: // Error: incompatible... more 10/23/2014 8:25:52 PM

people

Format of the initialization string does not conform to specification starting at index 14

I am trying to connect to sql server database . I wrote vb.NET code to connect to database using bellow con. string: "Server=ABOODPC\aboodsrvr; Database=testDB1;Integrated...
Jon Skeet
people
quotationmark

The problem is that \a is being seen as an escape sequence (for "alert", U+007). The simplest approach is to use a verbatim string literal instead: @"Server=ABOODPC\aboodsrvr; Database=testDB1;Integrated Security=SSPI;" Alternatively,... more 10/23/2014 6:48:06 PM

people

C# Object reference not being modified

I have the following code: public static void Main() { Exception exception = new Exception("1", new Exception("2")); Exception inner = exception.InnerException; inner...
Jon Skeet
people
quotationmark

This should print an exception with message "1" and with an inner exception, that has the message "3" No, it shouldn't - because you're not modifying the object that the exception variable refers to at all. Instead, you're declaring a... more 10/23/2014 2:49:49 PM

people