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

Popular posts from this blog

c - How to retrieve a variable from the Apache configuration inside the module? -

c# - Constructor arguments cannot be passed for interface mocks -

python - malformed header from script index.py Bad header -