Reputation: 2716
In my main method, my first argument is a class PersonInfo lets say. How do I do this?
if(argument.equals(PersonInfo) {
//invoke method A
}
if(argument.equals(MyInfo) {
//invoke method B
}
Since arguments in main method are Strings, how do I check if these Strings equal my class name?
Upvotes: 3
Views: 2719
Reputation: 7824
You want to get the name of the class then compare it to your argument
.
if(argument.equals(PersonInfo.class.getSimpleName()))
{
//invoke method A
}
if(argument.equals(MyInfo.class.getSimpleName()))
{
//invoke method B
}
Upvotes: 1
Reputation: 240928
PersonInfo.class.getSimpleName()
is what you are looking for, and do it otherway so that you won't have to handle null
check
Upvotes: 4