javaメモリメカニズムの自己理解
2776 ワード
package com.ming.memory;
import org.junit.Test;
/* : * :byte、int、short、long * :float、double * :boolean * :char * :enum * */
/* String , new = , , new * , ( ) * */
public class BasicClass {
@Test
public void memoryKnow() {
byte a = 127;
Byte b = new Byte((byte) 127);
System.out.println(a == b);//a ,b Byte , b ,int intValue = b.intValue();, true
Byte c = 127;//Byte.valueOf(127); valueOf() , -128 127 Byte
Byte d = 127;
System.out.println(b == c);//b c new Byte , == , ,false
System.out.println(c == d);//c d -128 127 , Byte ,true
Boolean flag = null;
flag = new Boolean(true);
Boolean falg1 = new Boolean(true);
System.out.println(flag == falg1);// Boolean ,false
boolean flag2 = true;
System.out.println(flag == flag2);// Boolean,== booleanValue() ,true
}
@Test
public void testPackage() {
Integer a = 256;
int b = 256;
System.out.println(a == b);//true; “==” , , ( )
Integer c = 256;
System.out.println(a == c);//false; “==” ,
}
}