当前位置: 代码迷 >> J2EE >> Exception in thread "main" javassist.CannotCompileException
  详细解决方案

Exception in thread "main" javassist.CannotCompileException

热度:666   发布时间:2016-04-22 03:13:36.0
javassist 如何 写 泛型
我用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不支持泛型
------解决方案--------------------
泛型在运行时都擦除的,动态字节码的技术要支持来干嘛
------解决方案--------------------
关注关注
  相关解决方案