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
-
josh12382038ySo I'm not a java guy, but is (int 8).equals(int 8) really going to return false?
Nvm, see that they're strings now.. *facepalm * -
A common bug. The only solution is to press the power buttonβ and then never touch the power button again.
-
vringar16638ySorry, but βis that condition valid JS?
Come to think of it, please don't answer this question. I don't need any more reason to hate weakly typed languages. -
vringar16638y@stefano *sigh* yeah, extraordinarily funny ... But would this shit work in JavaScript?
I know it doesn't work in Java but want to know if he just went full retard or full retard and unable to do his errors right. -
Why it doesn't work: He gave a string as argument, "4+4" is equal to "4+4". 4+4 is equal to 8. It's a pretty uncommon mistake, because literally every code editor with syntax editor marks strings is another color than math logic.
-
@vringar I just checked and, as you can see, JavaScript is VERY broken. In the first assignment, the variable is a string but, if you increment it, it becomes a number. Even though the variable is now a number, it's not equal to 4. That's also why I don't use JS. π
-
Darkler15878y@stefano to be fair, if the ++ operator turned check into a number and incremented it, shouldnt check be 5 now? Thus satisfying the else?
While that is super sketchy type casting behavior at least the math checks out π -
Darkler15878y@stefano well it took me forever to figure out too because unlike js, "4" and 4 are 0% alike to us type safe devs haha
-
@Darkler the check variable is string because of 2+"2" so the value should be 22. So incrementing it would later would result in check variable having value 23.
And that's why there are scientific programming languages:
"Hey, you are the Java guy, aren't you? My Java is broken!"
Me: *Takes a look at the code*
if ("4+4".equals("5+3")) {
System.out.println("Same result!");
} else {
System.out.println("Different result!");
}
undefined