문제

Possible Duplicate:
Tricky ternary operator in Java - autoboxing

We know that int roomCode = null; is not allowed by the compiler.

Then why the Code 1 doesn't give a compiler error, when Code 2 does.

Code 1:

int roomCode = (childCount == 0) ? 100 : null;

Code 2:

int roomCode = 0;
if(childCount == 0) roomCode = 100;
else roomCode = null; // Type mismatch: cannot convert from null to int

올바른 솔루션이 없습니다

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top