0 Members and 1 Guest are viewing this topic.
static public void main(String[] s) { printType(String.class); printType("Hello".getClass()); printType(Integer.class);}static public void printType(Class c) { System.out.println(c.getName()); if (c.equals(String.class)) { System.out.println("Strings are cool!"); }}//Prints:java.lang.StringStrings are cool!java.lang.StringStrings are cool!java.lang.Integer
private void foo(Class<?> t){ if(t == String.class){ ... } else if(t == int.class){ ... }}private void bar(){ foo(String.class);}