ASM : Return a value
Hi. How, with ASM MethodVisitor, can I set the value my method returns ?
8 Replies
⌛
This post has been reserved for your question.
Hey @tyranobast! Please useTIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here./close
or theClose Post
button above when you're finished. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.
For example : make a method that returns 3.
the instructions you're looking for are
with what visit call ?
mv.visitIntInsn();
?
first: visitCode to start the code section
then: visitLdcInsn(3) for
ldc 3
, followed by visitInsn(Opcodes.IRETURN) for ireturn
dont forget to set the correct method return type in the descriptor, should be (whateverArgsYouWant)I
forgot: visitEnd afterwardsOk thank you very much!
If you are finished with your post, please close it.
If you are not, please ignore this message.
Note that you will not be able to send further messages here after this post have been closed but you will be able to create new posts.
Post Closed
This post has been closed by <@428632258413330442>.