Browsing 7239 questions and answers with Jon Skeet

equals not working with same value with different datatype

I have two objects as below: Object obj1 = new BigDecimal(123); Object obj2 = new Long(123); if(obj1.equals(obj2)) System.out.println("both are equal"); else ...
Jon Skeet
people
quotationmark

Is it comparing based on datatype? Yes, exactly as it's documented to. From BigDecimal.equals: Returns true if and only if the specified Object is a BigDecimal whose value and scale are equal to this BigDecimal's. And from... more 2/12/2015 10:12:36 AM

people

How to get Difference hours Between two date

I want get diffrences Day,Hour and Day between two days. I use belowe Code : DateTime LastDate = DateTime.Parse("2/12/2015 11:24:23 AM"); int differenceDay =...
Jon Skeet
people
quotationmark

You're subtracting component-wise (i.e. "this hour-of-day minus that hour-of-day, this minute-of-hour minus that minute-of-hour"). Don't do that - it won't work if the current hour-of-day is earlier than the hour-of-day of lastDate, or the... more 2/12/2015 8:39:59 AM

people

Class is present. But it complaints

package org.myorg; import java.security.PrivilegedExceptionAction; import org.apache.hadoop.conf.*; import org.apache.hadoop.security.UserGroupInformation; import...
Jon Skeet
people
quotationmark

The problem is the version of Hadoop you're compiling against. You're compiling against hadoop-0.20.1-dev-core.jar. I've just downloaded that, and javap shows the following for the UserGroupInformation class: public abstract class... more 2/12/2015 8:37:29 AM

people

How to properly check and handle null values or objects

var userDomain = (from a in this.db.DomainList.ToList() join b in this.db.UserDomain.ToList() on a.DomainId equals b.UserDomainId ...
Jon Skeet
people
quotationmark

Yes, if userDomain is null, then userDomain.DomainName will fail. In C# 6, you can get over this with the null conditional operator: string userDomainName = userDomain?.DomainName ?? "None"; Before C# 6, you need: string... more 2/12/2015 8:15:55 AM

people

SimpleDateFormat.parse and SimpleDateFormat.format not producing identical values

We are using SimpleDateFormat in JAXB serialization/deserialization process of java.util.Date objects and I'm writing following utility to accomplish that public DateFormat...
Jon Skeet
people
quotationmark

The two strings represent the same instant in time - it's just that one has a different UTC offset than the other. That's to be expected - a Date only represents a point in time, and it looks like you've set up your SimpleDateFormat using... more 2/11/2015 7:57:11 PM

people

Insert Datetime.now from asp.net into sql server

I'm trying to insert 'DateTime.Now' into sql column type of datetime but when insert is done in sql table date is OK! (exp: 2015-02-11) but time is stored as 00:00:00!!! I tried...
Jon Skeet
people
quotationmark

You're specifying a SqlDbType of Date - that doesn't have a time. So when the driver is converting the parameter value into the desired type, it's removing the time part. You're also converting DateTime.Now into a string for no obvious... more 2/11/2015 6:10:09 PM

people

ArrayList does not save my Values

following: I create a ArrayList with an Own Object which keeps two int(x,y) But I only get 0 instead of the number. I don't see why it does not work. public class Snake...
Jon Skeet
people
quotationmark

Look at your constructor: SnakeBody(int x, int y){ x = this.x; y = this.y;} That's copying the value from your instance field to the parameter, in both cases. In other words, you're overwriting the useful data (the value... more 2/11/2015 5:31:34 PM

people

Can I implement an implicit 'conversion' from string to boolean in C#?

There's any way to implement an implicit conversion from string to bool using C#? E.g. I have the string str with value Y and when I try convert (cast) to boolean it must return...
Jon Skeet
people
quotationmark

No. You can't create user-defined conversions which don't convert either to or from the type they're declared in. The closest you could easily come would be an extension method, e.g. public static bool ToBoolean(this string text) { ... more 2/11/2015 5:04:37 PM

people

Java Multi Catch/Rethrow

If I do the following using a multi-catch in Java 1.7: catch (ArrayIndexOutOfBoundsException | NullPointerException ex) { logger.error("Array out of bounds exception in...
Jon Skeet
people
quotationmark

Will the re-thrown exception maintain the exception type that originally entered the catch clause? Yes - it will rethrow the exact same exception object. You need to differentiate between the compile-time type of ex (which is... more 2/11/2015 4:35:09 PM

people

`rtserver id` turns to `rtserver id` in java string

I have this code: public void foo (){ String script = "var aLocation = {};" + "var aOffer = {};" + "var...
Jon Skeet
people
quotationmark

rtserver-id isn't a valid identifier - so if you want it as a field/property name, you need to quote it. You can see this in a Chrome Javascript console, with no need for any Java involved: > var aClientEnv = { sessionId: "",... more 2/11/2015 12:56:10 PM

people