Here you can find the source of cast(Object obj, Class
public static <T> T cast(Object obj, Class<T> clazz)
//package com.java2s; //License from project: Open Source License public class Main { @SuppressWarnings("unchecked") public static <T> T cast(Object obj) { return (T) obj; }/* w w w .j a v a2 s . c o m*/ /** * From a type point of view, this works ... however all call to this * function will perform the cast AFTER which sucks */ public static <T> T cast(Object obj, Class<T> clazz) { return clazz.cast(obj); } }