DulcetAirman

generic casting

Dec 19th, 2018
70
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package quiz.generics;
  2.  
  3. public class SomeClass {
  4.     static <T> T cast(Object object) {
  5.         return (T) object;
  6.     }
  7.     public static <Integer> void main(String[] args) {
  8.         String str = "123";
  9.         Integer i = SomeClass.<Integer>cast(str);      
  10.         System.out.println(i);
  11.     }
  12. }
RAW Paste Data