简体   繁体   中英

How to create parametrized class in byte-buddy?

How to create parametrized class in byte-buddy? For example:


    static public class SomeClass < T > {
      T value;
    }



    Class<?> dynamicType = new ByteBuddy()
                   .subclass(Object.class)
                   .defineField("value", ???, Modifier.PUBLIC)
                   .make()
                   .load(Main.class.getClassLoader())
                   .getLoaded();

As simple as:

new ByteBuddy().subclass(Object.class)
  .typeVariable("T")
  .defineField("value", TypeDescription.Generic.Builder.typeVariable("T").build(), Modifier.PUBLIC);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM