I have a request that am not able to solve:
Lets suppose I have this class:
public class DummyPoint {
private int x;
private int y;
private final String id;
/**
* @param x
* @param y
*/
public DummyPoint(int x, int y) {
this.x = x;
this.y = y;
if(am getting created by reflection??) {
this.id = UUID.randomUUID().toString();
}else {
this.id = "Reflected";
}
}
...
}
In my project that class DummyPoint can be instantiated by:
DummyPoint dp = new DummyPoint(0,0);
dp.getX();
dp.getY();
dp.getId();
BUT it can be generated by reflection too:
Question:
I would like to know if I can discriminate between an object generated by reflection or not like am trying to do in the constructor.
Is that possible???
What I tried so far:
final DummyPoint dp0 = DummyPoint.class.getConstructor(int.class, int.class).newInstance(0, 0);
final DummyPoint dp1 = new DummyPoint(0, 0);
// ??????
System.out.println(dp0.getId());
System.out.println(dp1.getId());
but both objects are not showing concrete differences in order to make a choice.
thanks
Aucun commentaire:
Enregistrer un commentaire