我用javassist添加字段时,需要用到泛型,但是不成功,请大家帮帮忙
-------------------------------------
ClassPool pool = ClassPool.getDefault();
CtClass ctClass = pool.makeClass("com.cs.test.Haha");
CtField cfield = CtField.make("public java.util.Set<java.lang.String> ss;",ctClass);
ctClass.addField(cfield);
-------------------------------------
Exception in thread "main" javassist.CannotCompileException: [source error] syntax error near "util.Set<String> ss;"
at javassist.CtField.make(CtField.java:168)
at com.cs.test.Test.main(Test.java:35)
Caused by: compile error: syntax error near "util.Set<String> ss;"
at javassist.compiler.Parser.parseMember1(Parser.java:54)
at javassist.compiler.Javac.compile(Javac.java:88)
at javassist.CtField.make(CtField.java:163)
... 1 more
------解决方案--------------------
javassist不支持泛型
------解决方案--------------------
泛型在运行时都擦除的,动态字节码的技术要支持来干嘛
------解决方案--------------------
关注关注