字节好友-如何使字段自类型?

时间:2019-05-13 16:27:47

标签: java byte-buddy

有必要描述此类的结构

app.use(function(req, res, next) {
  res.header("Access-Control-Allow-Origin", "*");
  res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
  res.header("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS");
  next();
});

尝试了解决方法:Byte-buddy: generate classes with cyclic types

但是会导致错误 java.lang.ExceptionInInitializerError 原因:java.lang.IllegalStateException:无法解析潜在类型描述的声明类型:...

1 个答案:

答案 0 :(得分:0)

您可以使用TargetType作为当前生成的类型的引用:

new ByteBuddy()
  .subclass(Object.class)
  .name("A")
  .defineField("listA", 
      TypeDescription.Generic.Builder.parameterizedType(
          List.class, TargetType.class).build(),
      Visibility.PRIVATE)
  .make()