191

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!");
}

Comments
  • 26
    So 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 *
  • 12
    Tell him he should be using ==. That's likely to be the root of the problem.
  • 12
    To be fair... HIS java is definitely broken.
  • 35
    A common bug. The only solution is to press the power button​ and then never touch the power button again.
  • 0
    Sorry, 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.
  • 10
    @vringar That's not JS, it's Java. 😁
  • 1
    Well, he had to implement a custom Eval class. Ah! I get it. It's a no brainer
  • 0
    "The equals method is bugged, shitty Java APIs" πŸ˜‚πŸ˜‚
  • 0
    @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.
  • 1
    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.
  • 2
    @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. πŸ˜‚
  • 4
    @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 πŸ˜‚
  • 1
    @Darkler You're right ahahah I guess I shouldn't write code when I'm sick πŸ˜‚
  • 4
    @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
  • 1
    @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.
Add Comment