سؤال

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)

هل كانت مفيدة؟

المحلول

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.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top