NullPointerException in ternary operator

1225 단어
java 코드:
Integer i = null;
Integer x = true ? i : 1;
 
assembly code:
public static void main(java.lang.String[]);
  Code:
   Stack=1, Locals=3, Args_size=1
   0:   aconst_null
   1:   astore_1
   2:   aload_1
   3:   invokevirtual   #2; //Method java/lang/Integer.intValue:()I
   6:   invokestatic    #3; //Method java/lang/Integer.valueOf:(I)Ljava/lang/Int
eger;
   9:   astore_2
   10:  return
 
null , Integer.intValue:() ,

Integer
public int intValue() {
    return value;
}
 
Integer x = null;  
int a = x.intValue();  // NullPointerException because x is null
 

좋은 웹페이지 즐겨찾기