java - Is there any way to know the type of an Object? -
the scenario passing object parameter in method , want perform operations based on type of object within method.
sample code is:
method(object object){ //if object== string type print string }
try
if (object.getclass().getname().equals("class1name")) //do something.
the advantage of getclass
instead of instanceof
not need know class type @ compile time.
Comments
Post a Comment