I can test the class type in a program where I'm working both with instanceof
or getting a field that identifies the class appartenency. so the choice is between
if(myObjec instanceof Something){
}
And
if(myObjec.geClassType().equals("Something")){
}
What is the best in terms of efficency?
geClassType()
is a method present in the object of the program where I'm working(not a standard java method) and is a method that returns a string wih the name of the class. the name is passed as field when the object is created
EDIT
the field that I get in the second sample in my code doesn't identify exactly the class but a category and is used also for different routines, but I can use this also for this purpose since I use a specific object for each category.
So I have reported this as getClassType
to make my question more clear.