Compare types.

I have a list with different types of objects in and I want to compare the selected objects type with a type, to see which type of object I have selected.Is that possible?
[185 byte] By [671944EikHorsa] at [2007-11-26 12:18:20]
# 1
Yes, the instanceof keyword.But this is not sounding very OO
642814zadoka at 2007-7-7 14:57:45 > top of Java-index,Archived Forums,Socket Programming...
# 2

if(obj instanceof Apple) {

// Apple selected

} else if(obj instanceof Banana) {

// Banana selected

} // and so on.

...

574718aniseeda at 2007-7-7 14:57:45 > top of Java-index,Archived Forums,Socket Programming...