I would like some help to understand why casting Object to Object returns true
on Output #5 and false
on Output #7 if eventually I think both are comparing same object being casted by same class.
Thanks you
class Test {
PVector a = new PVector(3, 2, 1);
float f = 2f;
}
Test t = new Test();
void setup() {
//copy variable from class
float cv = t.a.x;
println( cv == t.a.x ); //1, OUTPUTS: true
//get class
//println( cv.getClass() ); //Error: Cannont invoke getClass() on the primitive Type float
println( ((Object)cv).getClass() ); //2, OUTPUTS: class java.lang.Float
println( ((Object)t.a.x).getClass() ); //3, OUTPUTS: class java.lang.Float
//move to Object
Object ocv = cv;
Object otax = t.a.x;
//comparing objects
println( (float)ocv == (Float)otax ); //4 casting Float on float, OUTPUTS: true
//Dynanic cast
try {
Class c = ((Object)t.a.x).getClass();
Object b = Class.forName(c.getName()).cast(ocv);
println( ocv == b ); //5, casting Object on Object OUTPUTS: true
}
catch(Exception e) {
}
println( ocv == (Float)otax ); //6, casting Float on Object OUTPUTS: false
println( ocv == otax ); //7, casting Object on Object OUTPUTS: false
}