Here you can find the source of cast(Object source)
@SuppressWarnings("unchecked") public static <T> T cast(Object source)
//package com.java2s; //License from project: Apache License public class Main { @SuppressWarnings("unchecked") public static <T> T cast(Object source) { try {//from w w w.ja v a 2 s . c o m return source == null ? null : (T) source; } catch (Exception e) { throw new IllegalArgumentException("Cannot convert to type"); } } }