ProjectCoinProposal

compared with
Current by john.rose
on May 01, 2009 12:38.

Key
This line was removed.
This word was removed. This word was added.
This line was added.

Changes (8)

View page history
(Rationale: Although it is strange for non-references to appear in the syntactic position of type arguments, this design is far simpler than inventing a completely new syntax for specifying the return type of the call site, as some early prototypes did.)
*1.4* For the purposes of determining the descriptor of the {{invokedynamic}} instruction, null arguments (unless casted to some other type) are deemed to be of reference type {{java.lang.Void}}. This is a pragmatic choice, compatible with the verifier and partially coherent with the meaning of the type {{Void}}, since it happens to allow only null reference values. Conversely, {{void}} method return values are reflected as null values. The type {{Void}} will appear only to the bootstrap method, and will serve notice that the call site contains an untyped null reference, rather than an explicitly typed reference.
*1.4* For the purposes of determining the descriptor of the {{invokedynamic}} instruction, null arguments (unless casted to some other type) are deemed to be of reference type {{java.lang.Null}}, if this type exists. The type {{java.lang.Null}} will appear only to the bootstrap method, and will serve notice that the call site contains an untyped null reference, rather than an explicitly typed reference.

{noformat}
InvokeDynamic.myPrintLine(null); // type (Void) -> InvokeDynamic
InvokeDynamic.myPrintLine(null); // type (Null) -> Object
InvokeDynamic.<void>foo((String)null, null); // type (String, Void) Null) -> void
{noformat}
An earlier version of this proposal contained a dynamic wildcard type (interface {{Dynamic}}) also useful for composing dynamic invocation sites. This has been moved into its own separate proposal.
*Q:* Why is null being inferred as Void Null instead the compiler raising an error? Let the user cast it to Object, etc. (R&eacute;mi Forax)
 
*A:* I went back and forth on this point while I was working with the code. At first (a) null was implicitly Object, then (b) it caused an error (as you suggest), then (c) it uses a marker type Void. The most correct thing would be (d) to use Neal Gafter's marker type Null, but this doesn't exist yet. I settled on (c) as an approximation to (d), because I considered the use case of simulating Java call sites, and null is fundamentally different from any other type; therefore it need to be reified somehow. There is no real downside to using the hack type Void even if (d) becomes available, since the only consumers of those type references are bootstrap methods (MOP machinery), and they will always need some sort of special case for null types anyway; the special casing can be extended to Null and Void deprecated when the time comes. Also, this use of the type Void has no impact on statically typed Java code.
*A:* I went back and forth on this point while I was working with the code. At first (a) null was implicitly Object, then (b) it caused an error (as you suggest), then (c) it used a marker type Void. The most correct thing is (d) to use Neal Gafter's marker type Null, so this spec. will interoperate with that type, when it is added. Staying with case (b) ruins the use-case of simulating Java call sites, since null is fundamentally different from any other type; therefore it needs to be reified somehow.

*Q:* Why didn't you choose to allow catching checked exceptions from InvokeDynamic method calls? (Josh Suereth)

The individuals who post here are part of the extended Sun Microsystems community and they might not be employed or in any way formally affiliated with Sun Microsystems. The opinions expressed here are their own, are not necessarily reviewed in advance by anyone but the individual authors, and neither Sun nor any other party necessarily agrees with them.

Copyright 1994-2009 Sun Microsystems, Inc.
Powered by Atlassian Confluence
Sun Guidelines on Public Discourse Privacy Policy Terms of Use Trademarks Site Map Employment Investor Relations Contact