I try to check the class of argument to create a method builder, but when the case the argument is primitive, i don’t find a way to do that ?
My code who’s don’t work !!!
void setup() {
Truc t = new Truc();
println(t.getClass());
println(t.getClass().getCanonicalName());
println(t.getClass().getName());
int value = 0;
println(value.equals(int.class));
println(value == Integer.TYPE);
println(value.isPrimitive());
println(value.getClass());
}
class Truc {
}
The 8 Java primitive datatypes aren’t objects/references/pointers in any way.
They’ve got no members & the access .
operator can’t be used on them!
Damn it !!! That’s was to make a system for the callback… That’s possible with Java 11 ? Because I believe the next Processing have a chance to turn with Java 11.
Finally I find a way to test :
int val = 1;
void setup() {
test(val);
}
void test(Object obj) {
println(obj.getClass());
}
// print: class java.lang.Integer
Of int there exists a object Int that I use in several places or Integer
Notice that datatype Integer isn’t the same as the primitive datatype int
.
Rather it’s an object wrapper/box for an int
primitive value:
Docs.Oracle.com/en/java/javase/11/docs/api/java.base/java/lang/Integer.html
The actual class that’d represent an int
is int.class, not Integer.class.
At the end class.int
and class java.lang.Integer
can do a same job ? if Yes that’s ok for me.
Don’t understand what you mean ?