Ebay Interview Question
Java DevelopersCountry: United States
Interview Type: In-Person
If you have the String representation of class name and list of Classes then you can just compare the String name with the simple name of each class. If a match is found then you can determine what class that object belongs to
Lets say you have
public static void main(String[] args){
String objName = "Integer";
// provided you have list of classes,
for(int i=0;i< classList.size(); i++){
if(classList.get(i).class.getSimpleName().equals(objName)){
// whatever you want to do
}
}
}
You can use Reflection. You can also use instanceof.
- Abhi October 17, 2015