Here you can find the source of castTo(Object o, Class
@SuppressWarnings("unchecked") public static <T> T castTo(Object o, Class<T> cls)
//package com.java2s; /******************************************************************************* * Copyright (c) 2012 Google, Inc./*from ww w . java 2s. co m*/ * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: * Google, Inc. - initial API and implementation *******************************************************************************/ public class Main { @SuppressWarnings("unchecked") public static <T> T castTo(Object o, Class<T> cls) { Class<? extends Object> oc = o.getClass(); if (cls.isAssignableFrom(oc)) return (T) o; System.out.println("ReflectionUtils.castTo() -- returning null"); return null; } }