Browsing 7239 questions and answers with Jon Skeet

Linq Join with group by merging results

I'm trying to merge the results from two tables in to a list and then display it in a dictionary where the key is the domain and the value is a list of urls from both...
Jon Skeet
people
quotationmark

It's not entirely clear, but I suspect you actually want to treat these two tables as equivalents - so you can project to a common form and then use Concat, then call ToLookup: var projectedSource1 = context.Source1.Select(x => new {... more 5/13/2015 10:09:33 AM

people

How do i force java methods to run specific implementations

I have 2 overloaded method, one which runs a superclass and one which runs a subclass. i would expect that when sending a subclass, java would know to run the method specific to...
Jon Skeet
people
quotationmark

Why is it happening Because the overload resolution happens at compile-time, and the compile-time type of the aClass variable is SuperClass How do i achieve my wanted result? Either change the compile-time type of aClass to... more 5/13/2015 9:39:02 AM

people

"Missing IN or OUT parameter at index:: 1" when adding ?' parameters to my query

I have a query constructed in Java to select records, and when constructing with the values ?', I'm getting a missing in and out parameter. If I add only ?, it is working...
Jon Skeet
people
quotationmark

Parameters aren't substituted into queries textually. I believe the simplest way to do what you want is to just use the ? on its own for the parameter, but add any leading or trailing values to the parameter itself. For example: String... more 5/13/2015 6:27:23 AM

people

How to roll back XML file in case of exception in c#

I am creating XML file in C# and write data in it. But in case f exception the file should roll back. But in case of exception, file is generated with incomplete format and data....
Jon Skeet
people
quotationmark

The simplest approach is to just build the whole document up to start with in-memory, and then only write it at the very end. That will almost certainly lead to simpler code even leaving aside the "don't write invalid date" side of things.... more 5/13/2015 6:04:57 AM

people

What is the use of ThreadLocal?

What is the use of ThreadLocal when a Thread normally works on variable keeping it in its local cache ? Which means thread1 do not know the value of same var in thread2 even if...
Jon Skeet
people
quotationmark

With multiple threads, although you have to do work to make sure you read the "most recent" value of a variable, you expect there to be effectively one variable per instance (assuming we're talking about instance fields here). You might... more 5/12/2015 5:41:31 PM

people

Why does <T extends Enum<T> & SomeInterface> compile, but not <T extends SomeInterface & Enum<T>>?

I can't understand why the method2 does not compile whereas method1 does compile. I am using Eclipse with JavaSE 1.7 and I got the following error on method2: Multiple markers...
Jon Skeet
people
quotationmark

If you look at the syntax for type parameter bounds in JLS 8.1.2 you'll see: TypeBound: extends TypeVariable extends ClassOrInterfaceType {AdditionalBound} AdditionalBound: & InterfaceType In other words, only the... more 5/12/2015 3:01:41 PM

people

Isn't accessing private fields and properties due to reflection a security issue?

I just recently found out here that it is possible (at least in c#) to look up private fields and properties due to reflection. I was surprised, although I knew that somehow...
Jon Skeet
people
quotationmark

The question now is, if anyone can access every field in my classes, this is kind of insecure, isn't it? Not everyone can. Only code with sufficient permissions - trusted code. Untrusted code is restricted quite a bit. On the other... more 5/12/2015 12:49:54 PM

people

Retrieve JSON attachment and its attributes

Background: I have stored a JSON document (id: 160d7237a5fd00501f4654a6c8b42f38) in a CloudantDB and put an attachment against the document. As you can see that below JSON...
Jon Skeet
people
quotationmark

The JSON you've got doesn't include the actual attachment - just metadata about it. From the documentation: To retrieve an attachment, make a GET request to https://$USERNAME.cloudant.com/$DATABASE/$DOCUMENT_ID/$ATTACHMENT. The body... more 5/12/2015 9:18:53 AM

people

Consume Extension method in non static class

All of the examples for extension methods that I have seen consume the extension method in a class like: class Program { static void Main() { ...Call extension...
Jon Skeet
people
quotationmark

These seem to work because the consuming class is static. No, that's incorrect. Extension methods definitely don't have to be consumed from static classes or static methods. However, they do have to be declared in a class which... more 5/12/2015 8:54:02 AM

people

Error occurred While try to parsing JSON String using java

I'm trying to parse the JSON string using java. I don't know How to do that, I searched lot in internet and I got some idea. With that I have build code, but it doesn't work. When...
Jon Skeet
people
quotationmark

That looks like it's a bug in JSON-simple to me. Using the org.json parser, it works fine. The problem is that it's trying to parse the value as an integer and it's outside the range of normal Java primitive integer types. It could parse... more 5/12/2015 6:22:34 AM

people