Sé que es antiguo puesto, pero miro caso muy similar y luego me votación: P
Responder a la pregunta original: solo operando se evalúa PERO:
@Test
public void test()
{
Integer A = null;
Integer B = null;
Integer chosenInteger = A != null ? A.intValue() : B;
}
Esta prueba arrojará NullPointerException
siempre y en este caso IF statemat no es equivalente a?: Operador.
El motivo es aquí http://docs.oracle.com/javase/specs/jls/se5.0/html/expressions.html#15.25. La parte sobre el boxeo/unboxing está envuelto, pero se puede entender fácilmente mirando:
"If one of the second and third operands is of type boolean
and the type of the other is of type Boolean
, then the type of the conditional expression is boolean
."
Lo mismo se aplica a Integer.intValue()
Saludos!
También es algo tan simple que puedes probarlo y ver qué sucede :) –
que te da información sobre una instancia en particular. Es mejor encontrar lo que dice el estándar. –