0
Why isn't the new operator is used to create objects in string and wrapper classes
1 Respuesta
0
There is a difference of ref pointer. String are store in the pool, special memory region. store only one copy of each litteral string and return the ref if the immutable copy is find.
You Can use the New operator with There classes. But it will create a New object store in the heap.
That's why :
String constantString1 = "test";
String constantString2 = "test";
constantString1 == constantString2 // true because same ref
But
String constantString1 = new String("test");
String constantString2 = New String("test");
constantString1 == constantString2 // false because not the same ref object