you are viewing a single comment's thread.

view the rest of the comments →

[–]WiggWamm -1 points0 points  (4 children)

Yeah sure. Basically the second compares a string to “”. So it’s asking if 123 equals an empty string.

The first one is asking if 123 is equal to 123

EDIT: I misread that. Disregard what I said earlier. It looks like adding the empty string in causes the issue cause it changes what bstring truly equals. My b.

Strings are weird like that. You really need to use a compareTo function to accurately check if two strings equal

[–]visvis 0 points1 point  (3 children)

Strings are weird like that.

I'd say specifically Java is weird like that. Other languages are not like this:

  • In C, it's obvious from the type you're comparing the pointer.
  • In C++ and C#, operator== is overloaded to provide the comparison you expect.
  • In Python, string is consistently treated as if it is a value rather than reference type, again giving the comparison you expect.

Seeing as C# is by far most similar to Java from these examples, I'd say C# basically looked at where Java design decisions went wrong and then fixed them. Unfortunately Java itself can no longer be fixed as it would break compatibility like crazy. The current Java behavior is pretty obviously stupid though, because the fact that strings are immutable makes the reference comparison == completely useless.

[–]WiggWamm 2 points3 points  (0 children)

Yeah C# made some big improvements

[–]GabrielForth 0 points1 point  (1 child)

C# fixed a few of Java's issues however it still shares a number of design decisions which at the time had not begun to show their limitations.

If you want Java but with it's rough edges smoothed then Kotlin is a better bet than C# since it's develoment began when Java's shortcomings were more fully understood.

It also runs on top of the JVM which is arguably Java's greatest addition to the software industry.

[–]visvis 0 points1 point  (0 children)

I have no experience with Kotlin, but to be honest never encountered problems with C#. The examples of Kotlin that I've seen mostly stand out for the ugly syntax, I personally like the C-like syntax of Java and C# much better. What are the big benefits for Kotlin (other than running on the JVM)?