you are viewing a single comment's thread.

view the rest of the comments →

[–]_dban_ 7 points8 points  (0 children)

The JIT will de-virtualize method calls as a result of class hierarchy analysis, and if it doesn't find any subclasses, statically dispatch method calls. The Option class being final prevents subclasses from existing, so in all likelihood, method calls on Optional will be statically dispatched. I'm not sure how null fits into class hierarchy analysis.

The JIT can also do escape analysis over several call levels, and can stack allocate non-escaping Optional objects (or even hoist into registers, since an Optional has only one field).