public <T>T cast(Object obj,Class<T> clz){
  if (!clz.isAssignableFrom(obj.getClass())) {
    return null;
  }
  return clz.cast(obj);
}

public < T > T cast ( Object obj , Class < T > clz ) { if ( ! clz . isAssignableFrom ( obj . getClass ( ) ) ) { return null ; } return clz . cast ( obj ) ; }
this method casts the supplied object to the nominated class . if the object cannot be cast to the provided type , then a null will be returned .
