-
Notifications
You must be signed in to change notification settings - Fork 693
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
More complex generic example #23
Comments
Multiple generic parameters are not so different from a single one. |
Hi @chibash , thank you for reply 😃 Sometimes what is easy to us is hard to another people that don´t use javassist every day. I solve my problem, trying a lot....many, many, many times... I will put here, so if you or another dev of javassist put it on a example/tutorial file it will be cool: Problem: retain ParametrizedType generic info at runtime for hibernate read it from AttributeConverter interface. Solution: Use ClassPool pool = ClassPool.getDefault();
CtClass cc = pool.get("your.base.generic.enum.converter.Type");
cc.setName("someRandomName");
ClassSignature cs = new ClassSignature(null, null,
// Set interface and its generic params
new ClassType[]{new ClassType(AttributeConverter.class.getName(),
new TypeArgument[]{
new TypeArgument(new ClassType("user.enum.Type")),
new TypeArgument(new ClassType("database.Type"))
})});
cc.setGenericSignature(cs.encode());
// Constructor that call base class constructor with argument
CtConstructor ctConstructor = new CtConstructor(new CtClass[]{}, cc);
ctConstructor.setBody("this(" + "user.enum.Type" + ".class);");
cc.addConstructor(ctConstructor); |
Documentation has only one example about using generics.
I couldn't find on internet how extend a class that defines more than one generic parameter
using javassist.
I have a class that I want to extend at runtime using javassist, but generic parameter need to exists at runtime for reflection (hibernate needs it).
So, I´m not posting this issue to get a response for my problem.
The issue is true, have no documentation and examples with use of generics in the real world (extends, implements, < T extends MyType < X < V > > , X, V >).
The text was updated successfully, but these errors were encountered: