Browsing 7239 questions and answers with Jon Skeet

"Click" Delegate to an instance method cannot have null 'this'

I know there are alot of questions allready to this topic. But I can't really seem to understand this whole delegate stuff. I'm kinda at a point where I just want it to work and...
Jon Skeet
people
quotationmark

Yes, that will happen if FindForm() returns either null, or something that isn't an instance of IntDrawForm. There's nothing particularly specific to delegates here - you'd get a similar result if you tried this as your second... more 3/1/2016 11:49:47 AM

people

SimpleDateFormat throws ParseException

Given the following String and formatter settings: final SimpleDateFormat formatter = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy"); final String date = "Mon Jan 25...
Jon Skeet
people
quotationmark

I suspect the problem is with the locale used in the SimpleDateFormat. By default, SimpleDateFormat takes the default locale of the system... so if you run this code in France, "Mon" won't be recognized as a day-of-week abbreviation, for... more 3/1/2016 11:07:31 AM

people

Java final class with constant

I must define a class which all it does is hold constants. public static final String CODE1 = "100"; public static final String CODE2 = "200"; Now I want use these values in...
Jon Skeet
people
quotationmark

Just to use the values, you certainly shouldn't instantiate the class. Just because you can access static members as if they were instance members doesn't mean it's a good idea. If the class really only contains constants - and if you're... more 3/1/2016 9:11:38 AM

people

StringUtils.isNumeric is undefined method

I have imported that library: import org.apache.commons.codec.binary.StringUtils; And tried to use some of methods, but failed: StringUtils.isNumeric("2398sdf"); IDE keep...
Jon Skeet
people
quotationmark

You're using the wrong StringUtils class. You're importing org.apache.commons.codec.binary.StringUtils, but it looks like you want org.apache.commons.lang.StringUtils or org.apache.commons.lang3.StringUtils. The first of these doesn't have... more 3/1/2016 9:06:11 AM

people

Wrong output of SimpleDateFormat with milliseconds ( SSSSSSS )

I am parsing MS SQL date with java.text.SimpleDateFormat but it is giving me wrong output. According to the documentation of SimpleDateFormat, it should parse correctly or may be...
Jon Skeet
people
quotationmark

You've specified that there are 2870000 milliseconds - which is 47 minutes and 50 seconds. It's important to note that in SimpleDateFormat, S is a milliseconds specifier, not a "fraction of second" specifier. Basically, if you're... more 3/1/2016 8:09:36 AM

people

Why is a subclass in Java an instance of the super class but not assignable to it?

For a very basic example: public class Human { //human stuff } public class Developer extends Human{ //developer stuff } Why is Developer an instance of Human, but the...
Jon Skeet
people
quotationmark

In normal English I would say, that a developer object is assignable from a human class, not the other way around. And the problem is your usage of the words "object" and "class" here. It should be: a Human variable is assignable from... more 3/1/2016 7:11:27 AM

people

Serializing "string list" to JSON in C#

(I'v restated my question here: Creating class instances based on dynamic item lists) I'm currently working on a program in Visual Studio 2015 with C#. I have 5 list strings...
Jon Skeet
people
quotationmark

I would suggest refactoring your code to start with - instead of having 5 "parallel collections", have a single collection of a new type, User: public class User { public string Name { get; set; } public string ImageUrl { get;... more 2/29/2016 10:00:06 PM

people

Why can't GetType() find types when invoked through a method group delegate?

We have a very simple program invoking the Type.GetType static method. Both examples should return a valid type instance. Only the second one actually is. Looks like something odd...
Jon Skeet
people
quotationmark

This is really interesting. It's a mixture of the behaviour of Type.GetType(string) in terms of the calling assembly, and how method group conversions work. First, the Type.GetType documentation includes this: If typeName includes the... more 2/29/2016 2:36:11 PM

people

Java: How to iterate over days in a Period object

If I have a Period object defined like this: Period.between(LocalDate.of(2015,8,1), LocalDate.of(2015,9,2)) how to iterate over all days starting from first day until the last...
Jon Skeet
people
quotationmark

You can't - because a Period doesn't know its start/end dates... it only knows how long it is in terms of years, months, days etc. In that respect, it's a sort of calendar-centric version of Duration. If you want to create your own, it... more 2/29/2016 11:49:16 AM

people

Java Combo Box Diamond Operator not supported in source 1.6

Background I have developed a program which manipulates data in a database. That however, isn't the problem I have, so I will get straight to the point. I made a Combo Box on...
Jon Skeet
people
quotationmark

I assume that source 1.6 corresponds to the JDK that you have. So surely you only have source 1.6 if you have JDK 1.6. But have JDK 1.8 and Netbeans 8.0.2, so how come Netbeans says I use source 1.6? Well, not quite - it corresponds... more 2/28/2016 8:34:11 PM

people