In my program, I deal with classes and primitive types. If a program finds a class, it simply makes one of the following calls:
Class.forName(classname)cc.toClass() where cc is an instance of CtClass
However, if it finds a primitive type, things get worse:
Class.forName not used; it cannot be used with primitive types.cc.toClass() returns null
You can call the TYPE field from a wrapper class of primitive types, but how can I do this with reflection?
Here is my code:
CtClass cc;//Obtained from caller code Class<?> classParam; if (cc.isprimitive()) { classParam= ?? // How can I get TYPE field value with reflection ? } else { String nomClasseParam = cc.getName(); if (nomClasseParam.startsWith("java")) { classeParam = Class.forName(nomClasseParam); } else { classeParam = cc.toClass(); } }
Javassist 3.12.0.GA
EDIT: I posted the solution that I selected in the comments below. Anyway, I noted Tom's answer .
source share