Any::isNull check

Brian Goetz brian.goetz at oracle.com
Wed Dec 16 16:04:52 UTC 2015



On 12/16/2015 10:52 AM, Vitaly Davidovich wrote:
>
>     If you're working with an any-T, you don't know whether its a
>     reference or value.  So you still have to worry about NPE.
>
>
> Wouldn't the "right" thing to do, then, be specialize the method in 
> question for ref vs value types differently? You'd then also ensure 
> the dead code for value types wouldn't be in the bytecode as well.

Depends what you mean by "right", and depends who is the implicit 
subject of the sentence.

If you mean that the developers should write two versions of each 
method, one for nullable and one for not, that would be ridiculous. 
Duplicating N lines of code because one line of a method has to do a 
null check would be terrible.  (Spend a half hour trying to port the 
Collections code with that approach, and ask yourself if you can 
honestly ask people to code that way.)

If you mean that the static compiler should generate two separate 
versions based on a single source representation of the code, you are 
gaining the small optimization of early localized dead-code-elimination 
at the cost of more duplication.  Maybe that's "right", maybe that's 
foolish.


More information about the valhalla-dev mailing list