Skip to content

Instantly share code, notes, and snippets.

@rac021
Created November 8, 2017 15:45
Show Gist options
  • Select an option

  • Save rac021/a246dd60a89eac2da611623cca7bc6d3 to your computer and use it in GitHub Desktop.

Select an option

Save rac021/a246dd60a89eac2da611623cca7bc6d3 to your computer and use it in GitHub Desktop.
package entypoint;
/**
*
* @author ryahiaoui
*/
public class TGenericTest {
public static void main(String[] args) {
Integer callMe = callMe( 10, Integer.class ) ;
System.out.println(" --> " + callMe) ;
Boolean bool = callMe( true, Boolean.class ) ;
System.out.println(" --> " + bool) ;
}
public static <T> T callMe( T t ,Class<T> clazz ) {
return clazz.cast(t) ;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment