Integer version = (isSomeCondition? someObject.getInteger() : -1);
When the return value of someObject.getInteger()is null the code will cause a NullPointerException because the JVM would first un-box the Integer to make it match the type of the -1 (int).
One thing I wonder is which Java rule makes the JVM prefer un-boxing the someObject.getInteger() to boxing the -1?
Drop me line if you know.
No comments:
Post a Comment