Here you can find the source of as(Class
Parameter | Description |
---|---|
targetClass | a parameter |
entity | a parameter |
@SuppressWarnings("unchecked") public static <T> T as(Class<T> targetClass, Object entity)
//package com.java2s; //License from project: Open Source License public class Main { /**//from w ww . j av a2 s. c om * Casts {@link entity} to {@link targetClass} or return null, if it is impossible * * @param targetClass * @param entity * @return */ @SuppressWarnings("unchecked") public static <T> T as(Class<T> targetClass, Object entity) { T result = null; if ((entity != null) && targetClass.isAssignableFrom(entity.getClass())) { result = (T) entity; } return result; } }