Q:

How to get actual class type from Class method argument

I am trying to get the instance or class name from the method argument as follows :
public class Test {

   public void getData (Class<T> type){
     // Class type of instance of "type" method argument.
      if(type instanceOf SomeClass) {
        //Do something
      }
   }
}

I have already tried reflation methods like getClass(), getSimpleClassName(), getName() etc. These all are returning class name as "Class" and instance as "class java.lang.Class". I need it to compare the instance with some class and do necessary operation.

A:

If the types should be exactly the same (equals for example String.class and String.class then you can use == or equals)
public class Test {

   public void getData (Class<T> type){
     // Class type of instance of "type" method argument.
      if(type.equals(SomeClass.class) {
        //Do something
      }
   }
}

ELse if the types are related by inheritance e.g CharSequence.class and String.class you can use assignableFrom
public class Test {

   public void getData (Class<T> type){
     // Class type of instance of "type" method argument.
      if(SomeClass.class.isAssignableFrom(type) {
        //Do something
      }
   }
}

