public <T>T asClass(Class<T> clazz,T defaultValue){
  if (value == null)   return defaultValue;
  try {
    return clazz.cast(value);
  }
 catch (  ClassCastException e) {
    return defaultValue;
  }
}

public < T > T asClass ( Class < T > clazz , T defaultValue ) { if ( value == null ) return defaultValue ; try { return clazz . cast ( value ) ; } catch ( ClassCastException e ) { return defaultValue ; } }
convert the variant value to any class . if it cannot be converted returns defaultvalue .
