Browsing 7239 questions and answers with Jon Skeet

Passing getter/setter as a method reference

I have a bunch of entries like these two: if (update) { if (activity.getName() == null) { logger.debug(" Setting name on " + id); ...
Jon Skeet
people
quotationmark

Well you could refactor that particular code to: logUpdate(update, activity.getName(), name, "name", id); activity.setName(name); logUpdate(update, activity.getPlannedDuration(), plannedDuration, "planned duration",... more 10/1/2013 6:08:53 AM

people

java.util.Date class with different approach for same date gives different output

public static void main(String[] args) throws ParseException { // create a date Date date = new Date(); long diff = date.getTime(); Date date1 = new Date(2013, 10,...
Jon Skeet
people
quotationmark

This line: Date date1 = new Date(2013, 10, 1, 11, 6); ... doesn't do what you thing it does. That creates a Date object representing November 1st in the year 3913, at 11:06 local time. I don't think that's what you wanted. Indeed, if... more 10/1/2013 5:46:40 AM

people

error "Unable to cast object of type 'System.Int32' to type 'System.Collections.Generic.List`1[System.Int32]'"

I have an package delivery application and I am getting an error in my code below: public class DeliveryDriver { public List<int> DriverID { get; set; } public...
Jon Skeet
people
quotationmark

The error message says it all - the DriverId field in each row is an int, not a List<int>. Ditto for DriverName being a string, not a List<string>. You should change your DriverId and DriverName properties to be int and string... more 9/30/2013 9:35:36 PM

people

Simultaneous reading and changing the variable by different threads

I am interested in the situation where one thread is waiting for change of a variable in the while loop: while (myFlag == false) { // do smth } It is repeating an infinite...
Jon Skeet
people
quotationmark

Can the reader-thread see the result of changing the value of the variable in the other thread if this variable is NOT volatile? It may be able to, yes. It's just that it won't definitely see the change. In general, as I... more 9/30/2013 9:26:58 PM

people

How to convert to a Date from Timestamp

The two below JSON valus (created, udated) are some type of timestamp. The provider (Edmunds API) didn't specify anything besides "timestamp". I have tried standard UNIX...
Jon Skeet
people
quotationmark

Your current code assumes the value is in seconds - whereas it looks like it's in milliseconds since the Unix epoch. So you want: private static readonly DateTime UnixEpoch = new DateTime(1970, 1, 1, 0, 0, 0, ... more 9/30/2013 8:34:05 PM

people

Clear an Object already inserted to a hashmap

calls is an arrayList, customerCalls is a hashMap. I was debugging using eclipse and I fount that calls.clear clear the arrayList object already inserted in the customerCalls...
Jon Skeet
people
quotationmark

I am confused because I thought that once the object was submitted to another data structure, it has an independent entity and no operations can be taken on it unless I access this data structure containing it. No. The map contains a... more 9/30/2013 8:15:11 PM

people

Increment array value using array[key]++

My Java code: if(wins.containsKey(winner)) { int currentCount = wins.get(winner); wins.remove(winner); wins.put(winner, currentCount...
Jon Skeet
people
quotationmark

Firstly, I strongly suspect that this isn't going to be a performance bottleneck. As ever, test the simplest code that works before you use more complicated code. You could use AtomicInteger instead of Integer as the value type of your... more 9/30/2013 7:01:48 PM

people

Accessing returned object in Loop

I had a quick question, Right now I have a method that returns a populated DTO object, in another class I am calling that method, and then trying to get access to some of the...
Jon Skeet
people
quotationmark

It's not clear from your question, but I suspect that this: rewardServicesImpl.getAccountRewardSummary(request); should be: result = rewardServicesImpl.getAccountRewardSummary(request); If you want to use the value returned from a... more 9/30/2013 6:48:00 PM

people

Is current time within range

I know this question has been asked manytimes but mine has a small twist. There are many different shifts at work and I have two string shiftStart and shiftEnd. (example "6:00:00...
Jon Skeet
people
quotationmark

Firstly, make all the business logic deal just with time-related types. (Personally I'd use my Noda Time library with its LocalTime type for this work, but...) The parsing can come in the calling code. The logic is reasonably simple: if... more 9/30/2013 6:42:14 PM

people

C# Reflection Object does not match target type

I'm trying to use the propertyInfo.SetValue() method to set an object property value with reflection, and I'm getting the exception "Object does not match target type". It...
Jon Skeet
people
quotationmark

I suspect you just want to remove the second line. What's it doing there anyway? You're fetching the value of the property from the object referred to by businessObject - and setting that to the new value of businessObject. So if this... more 9/30/2013 6:32:34 PM

people