Ho questa domanda intervista:Integer specifico (Java Core)
public Integer v1 = 127;
public Integer v2 = 127;
public Integer v3 = 513;
public Integer v4 = 513;
public void operatorEquals(){
if (v1==v2)
System.out.println("v1 == v2");
else throw new RuntimeException("v1 != v2");
if (v3==v4)
System.out.println("v3 == v4");
else throw new RuntimeException("v3 != v4");
}
**Result**: java.lang.RuntimeException: **v3 != v4**
si può spiegare: perché? Non ho suggerimenti.
Non sospirerei _that_ much. –
Puoi spiegare più dettagliato ...? – user2171669
Ho modificato per mostrare il codice di 'Intero # valoreOf()'. Come puoi vedere, tra IntegerCache.low (-128) e IntegerCache.high (+127), in realtà non crei un nuovo numero intero. –