You cannot do this in Java because generics are not protected. You can use the so-called "type tokens", but it has limitations.
static <T> T construct(Class<T> klazz) {
try {
return klazz.newInstance();
} catch (InstantiationException e) {
return null;
} catch (IllegalAccessException e) {
return null;
}
}
System.out.println(construct(String.class).isEmpty());
Class<?>.newInstance() , (, nullary).