Live data from Hacker News

WTF Java? Why Not Overload == for Java.lang.Long?

stackoverflow.com

1–4 of 4 posts

Re: WTF Java? Why Not Overload == for Java.lang.Long?

#3
post #2

This particular quirk also holds true of, say, Ruby or Python: 256 is 256 # True (2**50) is (2**50) # False albeit without Java's fear of operator overloading and the counterintuitiveness it causes.

Comparison works as expected in Ruby Have checked in ruby 2.1.2p95

code:

> (250).class #=> Fixnum > (250) == (250) #=> true > (2100).class #=> Bignum > (2100) == (2100) #=> true

Re: WTF Java? Why Not Overload == for Java.lang.Long?

#4
post #3
post #2

This particular quirk also holds true of, say, Ruby or Python: 256 is 256 # True (2**50) is (2**50) # False albeit without Java's fear of operator overloading and the counterintuitiveness it causes.

Comparison works as expected in Ruby Have checked in ruby 2.1.2p95 code: > (2 50).class #=> Fixnum > (2 50) == (2 50) #=> true > (2 100).class #=> Bignum > (2 100) == (2 100) #=> true

Comparisons work, but Ruby's == isn't the same as Java's; what I was referring to was

    250.object_id == 250.object_id         # true
    (2**70).object_id == (2**70).object_id # false