java - Why do DUP when creating new instance -
Currently I'm just in a project that uses Java bytecode, I usually see that when a new class If you create an example and apply a method to it, then the byte code will be:
New & lt; MyClass & gt; DUP INVOKESPECIAL & lt; MyClass & Lt; Init & gt; & Gt; Why should "DUP" be here? With VM space, I get the details "Duplicate the top value on the operand stack and press the duplicated value on operand stack". But why is it necessary to duplicate the top value on the operand stack? Thank you.
"post-text" itemprop = "text"> Because INVOKESPECIAL will consume the value created by the operand stack by NEW, but you may actually need this to use this value , So the reference has been duplicated in advance.
Comments
Post a Comment