Browsing 7239 questions and answers with Jon Skeet

Nodatime BclDateTimeZone EqualsImpl throws NotImplementedException

The EqualsImpl method in the Nodatime BclDateTimeZone class throws a NotImplementedException. It is documented to behave in this way - is there a reason for this? If testing...
Jon Skeet
people
quotationmark

It is documented to behave in this way - is there a reason for this? Yup - it's basically very hard to determine zone equality in a general way. Suppose we have two BclDateTimeZone instances which wrap two distinct TimeZoneInfo... more 11/12/2014 5:40:11 PM

people

Generics have unexpected behaior using primitives array instead of wrapper array

The following code is returning a List of Integer: Integer[] arr = new Integer[] {3,2,1}; List<Integer> list = Arrays.asList(arr); Why is the same code using "int"...
Jon Skeet
people
quotationmark

Yes, it's treating that as a call using varargs and int[] as the type argument, i.e. List<int[]> list = Arrays.<int[]>asList(new int[][] { arr }); The alternative would be to infer T=int... which is impossible, as Java... more 11/12/2014 5:33:15 PM

people

Obtain all middle elements IEnumerable LINQ

I have an array Y with containing ints e.g [1 3 2 0 9 8 2], I want to select all the elements except first and last [3, 2, 0 , 9, 8, 2] to use them in further operations. This is...
Jon Skeet
people
quotationmark

dasblinkenlight's approach is probably the best if you're happy to restrict yourself to collections where you know the length beforehand. If you don't, you might want to add an extension method like this (untested): public static... more 11/12/2014 4:55:44 PM

people

Must every function in the subclass be defined in the superclass?

class shape { private String name; public shape(){ System.out.println("in shape, default"); } public shape(String n){ System.out.println("in shape,...
Jon Skeet
people
quotationmark

The problem is that the compile-time type of your newObject variable is shape. That means the only members that the compiler knows about are the ones in shape, and that doesn't include f(). If you want to use members which are specific to... more 11/12/2014 2:58:08 PM

people

Is StreamReader.Read() a blocking method?

Is StreamReader.Read() a blocking method especially if applied to a NetworkStream?
Jon Skeet
people
quotationmark

Yes - it blocks until one of the follow conditions is satisfied: A character is read The end of the underlying stream is reached The underlying stream throws an exception more 11/12/2014 2:49:02 PM

people

cannot await object in the async call

I have a method called DoSomething() that returns an object and is time-consuming. So I would like to use async/await to let it run in the background while my GUI is showing a...
Jon Skeet
people
quotationmark

I think you've misunderstood how async and await works. If DoSomething() is a long-running method which isn't designed for asynchrony, you probably just want to do it in a different thread, e.g. by starting a separate... more 11/12/2014 2:40:29 PM

people

Prevent “Access to a static member of a type via a derived type” when deriving classes having structs with string constants

I'm wrapping the ForgeRock REST API implementation in C#. That implementation is layered. There is a base layer on the ForgeRock level, which gets extended for each of their...
Jon Skeet
people
quotationmark

I think in this confined case, it is OK to have this kind of naming. Well, personally I disagree. It's generally bad for readability when the same name means different things within a program - it's even worse (IMO) when those two... more 11/12/2014 2:17:53 PM

people

Unit testing a void method

I understand that you can unit test a void method by checking for its effects. However, looking at the loadConfigFile method in this code: internal XmlDocument configData; ...
Jon Skeet
people
quotationmark

You could test that getConfigValue returned the values loaded from the file, basically. Just because you test setConfigValue/getConfigValue in other tests doesn't mean that you can't use them in the test for loadConfigFile. As an aside,... more 11/12/2014 12:58:25 PM

people

Overloaded extension method is not being called

If we have a simple class like this one: class MyClass { public void DoSomething(object anObj) { Console.WriteLine("I am an Object: {0}", anObj); } ...
Jon Skeet
people
quotationmark

Could someone explain this behaviour? Sure - extension methods aren't considered until after the compiler has failed to find a normal instance method to call. They're not part of the normal candidate set. If you do something that... more 11/12/2014 11:07:11 AM

people

how to convert date and time to 12 hour format

hello i have a date and time string in 24 hour format but i want it in 12 hour how i can do this my string is String date_st="12 Nov, 2014 23:13" i am doing this ...
Jon Skeet
people
quotationmark

You need two formats: one to parse, and one to format. You need to parse from String to Date with one DateFormat, then format that Date into a String with the other format. Currently, your single SimpleDateFormat is half way between -... more 11/12/2014 8:52:25 AM

people