Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
enoon4237y@AlgoRythm I know that in JS, there’d be some iffy type conversion to at least try to solve the comparison. So it change the type of the rand hand expression to the type of the left (so a String object). Since it’s using “==“ instead of .equals() as you observed, it’d be comparing if the objects are the same, that is, if they point to the same location in the heap. Since one is a literal, and one is actually declared at that very moment, they probably don’t point to the same location.
So it’d be false. I’m not sure if Java does this though. -
@enoon it does. So yeah, the condition is syntactically correct. It's also always false as it compares refs rather than values
-
aaxa22217y@AlgoRythm as has already been mentioned, this will definitely work. It will just always be false ;)
Related Rants
So I'm cleaning up some buggy Java code when suddenly this dandy fine line appears:
if (new Double(a).toString() == "1.3") ...
Someone got paid for this :|
rant
excellent
java