Browsing 7239 questions and answers with Jon Skeet

Error Timestamp format

I'm trying to retrieve a Timestamp from my DB and I need to convert it to a java.util.Date I've been following several examples I've found in stackoverflow but I keep getting the...
Jon Skeet
people
quotationmark

Stop converting the values to strings and back. A java.sql.Timestamp already is a java.util.Date: long now = System.currentTimeMillis(); while (rs.next()) { Timestamp ts = rs.getTimestamp("HIGH_VALUE"); long diff = ts.getTime() -... more 8/11/2014 4:18:16 PM

people

Cannot convert functional interface with generic method into lambda expression

Cannot convert functional interface with generic method into lambda expression. Following code is working. It is without lambda expression i.e. using anonymous class. public...
Jon Skeet
people
quotationmark

The main problem is that you've got a generic method instead of a generic interface. That doesn't make a lot of sense. As soon as you make the interface generic instead, it works: @FunctionalInterface interface Pro<T> { void... more 8/11/2014 2:22:27 PM

people

List of objects to Dictionary with distinct keys and selected values

I have a List of objects of following class: class Entry { public ulong ID {get; set;} public DateTime Time {get; set;} } The list contains several object per ID value,...
Jon Skeet
people
quotationmark

Sounds like you want to group by ID and then convert to a dictionary, so that you end up with one dictionary entry per ID: var dictionary = entries.GroupBy(x => x.ID) .ToDictionary(g => g.Key, ... more 8/11/2014 1:51:41 PM

people

Why two objects of a specific class with same properties and functions are not equal in java?

In the below code It prints "NotSame" Can any one tell me the reason thanks in advance... public class student { String name; student(String name) { this.name...
Jon Skeet
people
quotationmark

This line: if (s1 == s2) compares the values of the variables s1 and s2. Those values are just references. In other words, it's asking whether the values of s1 and s2 refer to the same object. They clearly don't, in this case. To ask... more 8/11/2014 1:44:32 PM

people

Java autoboxing and unboxing

I am trying to convert and array ints to a List however every time I try I get a compilation error. List<Integer> integers =...
Jon Skeet
people
quotationmark

Yes, you can't do that, basically. You're expecting to be able to call toList with a type argument of int, and Java doesn't allow primitives to be used as type arguments. You basically need a different method for each primitive you want to... more 8/10/2014 7:57:09 PM

people

C# JSON.Net parse and get list of all elements matching a value using LINQ

I'm having trouble finding the correct method for getting a list of json arrays from JObject. _name element inside the array should be equal to foo. This is the sample json: { ...
Jon Skeet
people
quotationmark

Three problems: You don't want the direct children of doc, you want the descendants. You're using x["_name"].Value<string>() even if there is no _name property You're using x["_name"].Value<string>() even on non-object... more 8/10/2014 5:13:22 PM

people

Dictionary to List of Keys on Conditional Match

Say I have this dictionary: ConcurrentDictionary<string, Location> connections; I want to get a list of the keys from this dictionary that match some conditions on their...
Jon Skeet
people
quotationmark

It's not clear why you've got the ToDictionary call at all. You just need a Select call: List<string> users = connections.Where(x => x.Value.IsNearby(anotherLocation) .Select(x => x.Key) ... more 8/10/2014 4:53:15 PM

people

Java FileWriter outputs a question mark

I have been unable to find the reason for this. The only problem I am having in this code is that when the FileWriter tries to put the new value into the text file, it instead...
Jon Skeet
people
quotationmark

You're calling Writer.write(int). That writes a single UTF-16 code point to the file, taking just the bottom 16 bits. If your platform default encoding isn't able to represent the code point you're trying to write, it will write '?' as a... more 8/10/2014 6:36:33 AM

people

ContinueWith as an alternative to the await operator

My application uses scripts. So far, I've used C# for the scripts and compiled them using the CodeDomProvider. However, I've been thinking about switching to Lua using the NLua...
Jon Skeet
people
quotationmark

Okay, as you now claim this has nothing to do with Lua, here's how you would call the method in C#, then log only when the task had completed: Task<bool> task = ReturnResult(); task.ContinueWith(t => Log("Returned " +... more 8/9/2014 8:50:21 AM

people

Why does methods for wrapping element in Set/List/Map contains 'singleton' in name ?(java.util.Collections)

I know if I had element and I want to get List/Set/Map with eith element only I should invoke : Collections.singleton() / Collections.singletonList() /...
Jon Skeet
people
quotationmark

It's a different meaning of the word "singleton" - it's not "the singleton pattern", it's "create a collection from a single item", that's all. For example, from define:singleton: a single person or thing of the kind under... more 8/9/2014 8:38:50 AM

people