1 year ago

#388400

test-img

Siva

String concatenation of compile time constants

I'm trying to understand the String concatenation process. The below initialized variables (a, b, str) are all compile time constants.

When concatenating the compile time constants and comparing it with the equivalent string literals, it should return true, right?

But here it returns true for primitive value and false for a Wrapper class (Integer) variable.

I've gone through a few other SO posts, but I don't get this.

What's happening here?

final int a = 0;
final Integer b = 0;
final String str = ":ZERO";

String str1 = a + str;
String str2 = b + str;

System.out.println(str1 == "0:ZERO"); // true
System.out.println(str2 == "0:ZERO"); // false

java

string

compile-time-constant

0 Answers

Your Answer

Accepted video resources