I found a rather strange thing for me while working with Java. This may be a common thing, but I don’t understand why it works this way.
I have a code like this:
Character x = 'B'; Object o = x; System.out.println(o == 'B');
It works fine, and the output is true. Then I change English B to Slavic B (B):
Character x = ''; Object o = x; System.out.println(o == '');
Now the output is false. How so? By the way, the output is still “true” if I compare the variable x with “B” directly, but when I do this through an object, it works differently.
Can anyone explain this behavior?
java object compare character
user2452103
source share