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?