Skip to content

Instantly share code, notes, and snippets.

@zaki50
Created January 20, 2011 07:04
Show Gist options
  • Save zaki50/787518 to your computer and use it in GitHub Desktop.
Save zaki50/787518 to your computer and use it in GitHub Desktop.
class Klass<K> {
public static <K> Klass<K> create(Class<K> c) {
return new Klass<K>(c);
}
private final Class<K> clazz;
private Klass(Class<K> c) {
clazz = c;
}
public K get() {
return clazz.newInstance();
}
}
Klass<String> k = Klass.create(String.class);
String s = k.get();
とか
Klass<? extends CharSequence> k = Klass.create(String.class);
CharSequence s = k.get();
みたいな使い方になるかと...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment