Generic method to cast - Java Reflection

Java examples for Reflection:Method

Description

Generic method to cast

Demo Code



public class Main{
    public static void main(String[] argv) throws Exception{
        Object temp = "java2s.com";
        System.out.println(cast(temp));
    }//from w w w .  ja v  a 2  s  . c o  m
    @SuppressWarnings("unchecked")
    public static <T> T cast(Object temp) {
        return (T) temp;
    }
}

Related Tutorials