Creating a new field with asm 4

帅比萌擦擦* 提交于 2019-12-13 04:35:02

问题


This is the code im using

    String fieldName = "lock";
    String fieldType = "Ljava/util/concurrent/locks/Lock;";
    Object initValue = new ReentrantLock();

    cw.visitField(ACC_PUBLIC, fieldName, fieldType, null, initValue).visitEnd();

Im attempting to add a line of "Lock lock = new ReentrantLock();" but asm is throwing a error

Exception in thread "main" java.lang.IllegalArgumentException: value class java.util.concurrent.locks.ReentrantLock at org.objectweb.asm.ClassWriter.a(Unknown Source)


回答1:


You cannot pass an object as an initial value. You need to generate the code which will create the object when the code is run, not when you generated the code.



来源:https://stackoverflow.com/questions/18949136/creating-a-new-field-with-asm-4

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!