Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

bytebuddy: make array of generic

i want to make class:

class Clazz<T>{
 T[] value;
}


TypeDescription.Generic t1 = TypeDescription.Generic.Builder.typeVariable("T").asArray().build();

new ByteBuddy().subclass(Object.class)
            .typeVariable("T")
            .defineField("value", t1, Modifier.PUBLIC)
            .make()

but i get exception

Exception in thread "main" java.lang.IllegalStateException: A symbolic type variable does not imply an erasure: T
at net.bytebuddy.description.type.TypeDescription$Generic$OfTypeVariable$Symbolic.asErasure(TypeDescription.java:5802)

how i can make T[] field?

like image 534
vladimir vyatkin Avatar asked Jun 29 '26 01:06

vladimir vyatkin


1 Answers

You stumbled upon a bug. Byte Buddy attempts to resolve TargetType references to identify the instrumented type's self type which is not done correctly for generic arrays. It will be fixed in the next version 1.10.11.

like image 79
Rafael Winterhalter Avatar answered Jul 01 '26 15:07

Rafael Winterhalter



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!