Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Is 0xFFFF0000 equal to -0x00010000 ?

darrylburkeAug 26 2007 — edited Aug 27 2007
Try this:
public class LongTest {
    
        public static void main (String[] args)
	{
            long long1 = 0xFFFF0000;
            long long2 = -0x00010000;
            
            System.out.println(long1 == long2 ?
                "long1 is equal to long2" :
                "long1 is not equal to long2");
            
            Long long1a = new Long(long1);
            Long long2a = new Long(long2);
            
            System.out.println(long1a.equals(long2a) ?
                "long1a is equal to long2a" :
                "long1a is not equal to long2a");
        }
}
The surprising thing is that researching the documentation reveals that this is expected behavior.

Is this a semantic bug, or what am I missing here?

Regards, Darryl
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Sep 24 2007
Added on Aug 26 2007
11 comments
417 views