Question About MethodHandles.findSpecial

Attila Szegedi szegedia at gmail.com
Tue May 5 09:13:53 PDT 2009


You're right; you can't replace the ANEW bytecode; what you can do  
though is, you can do an invokedynamic instead of doing the usual  
statically linked invocation of <init>. I.e. instead of

ANEW someClass
DUP
INVOKESPECIAL someClass.<init>

sequence you could use

ANEW someClass
DUP
INVOKEINTERFACE java.dyn.Dynamic."someAliasForTheConstructor"

and then have the bootstrap method invoke constructor.
Although more probably than not, bytecode verifier would stop such  
code from getting loaded, methinks...

Attila.

On 2009.05.05., at 17:15, Fredrik Öhrström wrote:

> What is the purpose of being able to invoke the constructor
> through a MethodHandle? The reason I am asking is because
> to me, it seems like we cannot perform a new through
> a MethodHandle. Which means that we have to generate a
> factory method (to which we can bind a MethodHandle) to
> create a new instance and then we can just as well put
> the call to the constructor there. Or am i missing
> something? :-)
>
> //Fredrik



More information about the mlvm-dev mailing list