77

When such people exist 🤷‍♂️ Wish I can undo what I saw 🙈 My day is already ruined 🤦‍♂️

Comments
  • 6
    Hah, I love shit like this.
  • 19
    Output is "3 = 12", not "3=12".
  • 1
    @eeee I love the way you see things.
  • 0
    @irene What exactly do you mean, why is the string concatenation (in this case implicit conversion) garbage? :o
    It's just a nice trick to "abuse" the interpretation strategy of Java :D
    In my opinion especially in Java implicit conversion is an awesome thing. Especially widening and autoboxing, that's something really helpful :D I think it's a good fact, that the compiler partly takes care of a thing like that. It usually means that the code is enhanced in efficiency when compiled which to me is a big advantage
  • 0
    @irene It's just a mathematical approach they took for this interpretation strategy.
    Because if you but brackets around "somethingElse" it's interpreted before concatenation.
    Basically it's relying on a rule similar to "multiply before you add", just in Java.
    I think it's quite convenient, what would you suggest as strategy? :o
  • 2
  • 0
    @irene what do you think about the following?

    String a = null;
    String b = "null";
    System.out.print(a + b);

    > nullnull

    I hate that null results in a NullPointerException always, except for strings!
  • 1
  • 0
    Good solution would also be a separate string concatenation operator
  • 0
    @irene That would mean more work as a programmer and more stuff to care about. It's a little similar to handling memory on your own. In Java you actually can't but it's a similar idea. You can handle conversion on your own in Java by stopping the implicit conversion with you doing explicit conversion or adopting to the hierarchy its based on. Same with memory in some languages, you can handle it on your own or just let the compiler do it (in this case gbc, because you can't do it yourself). But it's still a 2 way thing, you can prevent it if you want.
  • 0
    @underscores are brackets around a statement after a string not an easy enough solution? 😂
  • 0
    @irene Imagine you would have to take care of all the conversions by yourself, how much code that would be. It would make work with Strings very complicated 😅
    And just to be sure, do you mean explicit conversion for Strings and other stuff only or for everything else too, like numbers etc?
  • 1
    @irene I can't really think of a case where a person would need to add a string and an integer without intending for the integer to be displayed as a string. If you want to output string+int+int, you should really use string+(int+int). It's just more clear that way, and implicit coercion isn't an issue with that :P
  • 1
    @qwert sorry, i was busy looking up small indian towns on google maps and listening to kshmr

    @irene yeah it annoying but when are you gonna use sysout instead of a logger in prod code eh?
  • 0
    Also pretty sure it should be "proven" not "proved". Sounds bad to me...
  • 0
    @irene In that particular case I can absolutely understand you. I was rather thinking of different scenarios. It seems to me that it depends a bit of the use-case
Add Comment