I am learning RTTI in Java and I wrote a function like that:
static void select(Shape s, Class c)
{
if(s instanceof c)
s.setSelected(true);
}
//Calling function: select(shape0, Circle);
The problem is, I have no idea if passing Class as paremater is possible? Compilator says it's error, it can't find c. So I used different code to solve this problem:
static void select(Shape s,Object obj)
{
if(s.getClass().equals(obj.getClass()))
s.setSelected(true);
}
//Calling function: select(shape0, new Circle());
But I was wondering if something like first example is possible?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…