Eventuali duplicati:
intern() behaving differently in Java 6 and Java 7String stagista puzzle
Su questo blog ho trovato interessante puzzle String:
--- Citazione ---
String te = "te", st = "st";
//"test".length();
String username = te + st;
username.intern();
System.out.println("String object the same is: "
+ (username == "test"));
stampe sotto Java 7 aggiornamento 7.
String object the same is: true
ma rimuovere il commento dalla .length "test"(); la linea, o correre con Java 6 e la stampa
String object the same is: false
--- --- EOQ
Essere onesti non capisco il motivo per cui le uscite sono diverse. Potresti per favore spiegarmi qual è la causa di tale comportamento?
beh è 'false' in entrambi i casi –
sì @Jigar ha ragione, quando ho provato il codice, l'output è false sempre –
False o non differisce con la versione di Java. –