Hirdetés
- Apple MacBook
- Milyen asztali (teljes vagy fél-) gépet vegyek?
- Befutott a peronra a hardvervonat
- AMD K6-III, és minden ami RETRO - Oldschool tuning
- Szünetmentes tápegységek (UPS)
- Asztrofotózás
- Mini PC
- Milyen házat vegyek?
- Kormányok / autós szimulátorok topikja
- HiFi műszaki szemmel - sztereó hangrendszerek
Új hozzászólás Aktív témák
-
-
Jim-Y
veterán
válasz
SirRasor
#4228
üzenetére
Lehet hülyeséget írok, de ebben az esetben tényleg nem változtatod meg a string literál értékét, az immutable marad, ellenben a gyumolcs változó referenciáját ráállítod a string class egy objektumára ("barack"), így a gyumolcs ezentúl a barack string literálra fog mutatni a memóriában, és nem a körtére. A GC meg gondolom végzi a dolgát ezután a "körte"-n.
"Now we find that the value displayed by the myString variable has changed. We have defined immutable objects as being unable to change in value, so what is happening? Let's extend the example again to watch the myString variable closer.
String myString = new String( "old String" );
String myCache = myString;
System.out.println( "equal: " + myString.equals( myCache ) );
System.out.println( "same: " + ( myString == myCache ) );
myString = "not " + myString;
System.out.println( "equal: " + myString.equals( myCache ) );
System.out.println( "same: " + ( myString == myCache ) );
The result from executing this is:
equal: true
same: true
equal: false
same: false
What this shows is that variable myString is referencing a new instance of the String class. The contents of the object didn't change; we discarded the instance and changed our reference to a new one with new contents."
Új hozzászólás Aktív témák
A topicot kiemeltem. Valaki nem akar egy nyitó hsz-t írni?:))
- Apple iPhone 13 256GB,Használt,Dobozaval,12 hónap garanciával
- BESZÁMÍTÁS! Lian Li Galahad II 360ARGB white bontattlan vízhűtés garanciával hibátlan működéssel
- 278 - Lenovo Legion Pro 7 (16IAX10H) - Intel Core U9 275HX, RTX 5080
- AKCIÓS ! MacBook Pro 16" M1 Pro 16GB RAM 512GB SSD! 1 év garancia!
- Apple iPhone 13 128GB,Átlagos,Adatkabel,12 hónap garanciával
Állásajánlatok
Cég: Laptopműhely Bt.
Város: Budapest


