Why isn't the new operator is used to create objects in string and wrapper classes | Sololearn: Learn to code for FREE!
Neuer Kurs! Jeder Programmierer sollte generative KI lernen!
Kostenlose Lektion ausprobieren
0

Why isn't the new operator is used to create objects in string and wrapper classes

19th Oct 2022, 4:27 AM
harsh singh
harsh singh - avatar
1 Antwort
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
19th Oct 2022, 6:23 AM
Roland
Roland - avatar