Browsing 7239 questions and answers with Jon Skeet

Why doesn't Stream#reduce implicitly accept an accumulative function handling super type elements?

Considering these classes and accumulation function, which represent a simplification of my original context (yet reproducing the same problem): abstract static class Foo { ...
Jon Skeet
people
quotationmark

The problem is that you're definitely creating a BinaryOperator<Foo> - you have to be, as you're returning a Foo. If you change combined() to be declared to return Bar (while still accepting Foo) then you'd be fine. It's the fact... more 5/14/2016 4:16:08 PM

people

Where is the source code for System.String for .Net Core?

The String class for older versions should be at http://referencesource.microsoft.com/#mscorlib/system/string.cs. Where can I find the class for .Net Core. And also where can I...
Jon Skeet
people
quotationmark

All the .NET Core source code is on Github, broken into corefx for the BCL beyond the bits that the CLR really depends on and coreclr for the CLR and the core parts of the BCL (like string). stringnative.cpp is the native part of the... more 5/14/2016 12:57:34 PM

people

Parsing Json containing escape characters to JsonObject using Newtonsoft

I'm trying to parse json string to JsonObject but I'm having exception ("Bad JSON escape sequence: \x. Path 'original_query', line 8, position 35.") I know there are bad...
Jon Skeet
people
quotationmark

Your attempt at replacing failed because you were using a C# string literal where \x is a C# escape sequence. You could have used something like: json = json.Replace("\\x22", "\\\""); ... which would replace \x22 with \" in the... more 5/14/2016 8:57:53 AM

people

ExecuteNonQuery C# & SQL Server

Here is my error: An exception of type 'System.Data.SqlClient.SqlException' occurred in System.Data.dll but was not handled in user code Additional information: The...
Jon Skeet
people
quotationmark

I suspect the problem is that you're specifying null as the value for @pro. From the docs for AddWithValue: Use DBNull.Value instead of null, to indicate a null value. However, I would also suggest avoiding using AddWithValue to... more 5/14/2016 8:52:08 AM

people

JDK 1.7 onwards, throwing an exception object from catch block does not require a throws clause!!! Why is this so?

I came across a weird scenario in java today while coding around. I have a try..catch block in my method which does not have any throws clause and I am able to throw the exception...
Jon Skeet
people
quotationmark

You'll see this if the code in the try block can't throw any checked exception. At that point, the compiler knows that the only kind of exception caught by the catch block has to be an unchecked exception, and so it can therefore be... more 5/12/2016 11:44:30 AM

people

C# hash table of array list is not printing any results

I am creating an hash table in C# then adding key for it and i am adding array list as values Then i am tring to print array list which is values but it is not working using...
Jon Skeet
people
quotationmark

This condition checks for a key with a value "one": variations_array.Contains("one") That doesn't exist - you've added a single entry with a key of "hi". That's why your first Console.WriteLine doesn't execute. Next: string sv = (... more 5/12/2016 9:43:41 AM

people

Passing getClass() as a parameter to a different class

1) I have a class called Utilites that performs some string checks to make sure an "ID" conforms to a standard. 2) I wanted to pass the details of the calling class to the...
Jon Skeet
people
quotationmark

You're calling getClass() on a java.lang.reflect.Type - so that's just going to give you Class.class... Effectively, you've called this.getClass().getClass(), and you don't want to do that. I suspect you want to change your validateId... more 5/12/2016 6:25:10 AM

people

Why strtotime subtracts 2 hours automatically?

I used strtotime("YYYY-MM-DD H:i:s") and this gave me a time 2 hours automatically subtracted. eg: strtotime("2016-05-11 00:00") gave me int(1462917600) this is 2 hours negative...
Jon Skeet
people
quotationmark

From the docs: Each parameter of this function uses the default time zone unless a time zone is specified in that parameter. So my guess is that you're in a time zone where 2016-05-11 00:00:00 local is 2016-05-10 22:00:00 UTC. The... more 5/11/2016 7:54:49 AM

people

java8 Interface allowing public default method

In java 8 default method implementation can take both public and default modifier. What is the main difference between below two methods. Under which conditions which type need to...
Jon Skeet
people
quotationmark

There's nothing special about default methods here. Java has always allowed interface methods to be declared public, even though they're already implicitly public. From JLS 9.4: Every method declaration in the body of an interface is... more 5/11/2016 6:30:45 AM

people

gzip: Inflate float array in java

I am trying to figure out a way to inflate/deflate an array of floats in java. My code to deflate looks like this, which seems to work fine. List<Float> floats =...
Jon Skeet
people
quotationmark

You're using different calls - you're calling writeObject in the writing part, then assuming that you can just read 4 bytes at a time in the reading part. Why not just use: Float[] floats = (Float[]) objectIn.readObject(); ? That would... more 5/10/2016 7:08:29 PM

people