I've got the following class which i want to use in my generated code with Javassist.
public class SomeClass {
private String someString;
private Object someValue;
public SomeClass() {}
public SomeClass(String someString, Object someValue) {
this.someString = someString;
this.someValue = someValue;
}
public void setSomeValue(Object someValue) {
this.someValue = someValue;
}
In Javassist i analyse some classes and their fields and then try to instatiate my SomeClass-class. But i get the following error for each field which has another type then java.lang.Object
.
javassist.CannotCompileException: [source error] setSomeValue(int) not found in com.test.SomeClass
and
javassist.CannotCompileException: [source error] setSomeValue(double) not found in com.test.SomeClass
and so on. The same happens when i try to use the constructor.
Why this doesn't work?
By the way, Javassist is used in conjunction with Android.
You need to differentiate between primitive datatypes and Classes:
A primitive datatype (byte
, short
, int
, long
, float
, double
, boolean
, char
) cannot be used like a class (like Object
in your case), in order to be able to use them as Objects
, you need wrapper classes (Integer
, Short
, Long
, etc.).
This is a basic of java, you should get yourself informed about primitive datatypes in java online: The Oracle Java Documentation may help you out.
You might also ask yourself why primitive datatypes are even neccessary when there are wrapper classes. You can find answers to that on this Stack Overflow question.