static <E>E checkType(E obj,Class<? extends E> type){
  if (obj != null && !type.isInstance(obj)) {
    throw new ClassCastException("Attempt to insert element of type " + obj.getClass() + " into collection of type "+ type);
  }
  return obj;
}

static < E > E checkType ( E obj , Class < ? extends E > type ) { if ( obj != null && ! type . isInstance ( obj ) ) { throw new ClassCastException ( "Attempt to insert element of type " + obj . getClass ( ) + " into collection of type " + type ) ; } return obj ; }
checks if specified object is instance of specified class . used for a dynamically typesafe view of the collections .
