Ú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?:))
- One otthoni szolgáltatások (TV, internet, telefon)
- LG LCD és LED TV-k
- Kínai és egyéb olcsó órák topikja
- NVIDIA GeForce RTX 5080 / 5090 (GB203 / 202)
- Fotók, videók mobillal
- Két 16 GB-os GeForce gyártását szüntette meg az ASUS
- Battlefield 6
- Milyen autót vegyek?
- SörcsaPH!
- Elektromos autók - motorok
- További aktív témák...
- Apple iPhone 14 Pro Max 256GB, Kártyafüggetlen, 1 Év Garanciával
- REFURBISHED és ÚJ - Lenovo ThinkPad Ultra Docking Station (40AJ)
- HIBÁTLAN iPhone 11 64GB Red-1 ÉV GARANCIA - Kártyafüggetlen, MS4388
- GYÖNYÖRŰ iPhone 12 Pro Max 256GB Graphite -1 ÉV GARANCIA - Kártyafüggetlen, MS2927, 100% Akkumulátor
- Dell Latutide E7270, 7280, i5- i7, 8GB RAM, 256gb ssd, EU bill., számla, 6 hó gar - több db
Állásajánlatok
Cég: Laptopműhely Bt.
Város: Budapest
Cég: PCMENTOR SZERVIZ KFT.
Város: Budapest

