rickygrimes
rickygrimes

Reputation: 2716

Check if String equals class name

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

Answers (2)

axwcode
axwcode

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

Related Questions