6

It is necessary to describe the structure of this class

class A{
    private List<A> listA;   
}

tried the solution: Byte-buddy: generate classes with cyclic types

but it will lead to an error

java.lang.ExceptionInInitializerError Caused by: java.lang.IllegalStateException: Cannot resolve declared type of a latent type description:...

Bashir
  • 2,057
  • 5
  • 19
  • 44

1 Answers1

3

You can use TargetType as a reference for the currently generated type:

new ByteBuddy()
  .subclass(Object.class)
  .name("A")
  .defineField("listA", 
      TypeDescription.Generic.Builder.parameterizedType(
          List.class, TargetType.class).build(),
      Visibility.PRIVATE)
  .make()
Rafael Winterhalter
  • 42,759
  • 13
  • 108
  • 192