Skip to content

Instantly share code, notes, and snippets.

@tamoot
Created May 2, 2015 15:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tamoot/a84e2e6bae67c2f74c3f to your computer and use it in GitHub Desktop.
Save tamoot/a84e2e6bae67c2f74c3f to your computer and use it in GitHub Desktop.
素人がGenericsを使おうとしたさんぷる
package sample;
public class HogeClient {
private Adapter adapter;
private static Class<? extends Adapter> staticAdapter;
public Adapter getAdaper() {
if ( staticAdapter != null){
try {
this.adapter = staticAdapter.newInstance();
} catch (InstantiationException | IllegalAccessException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}else if ( null == adapter){
this.adapter = new Adapter();
}
return adapter;
}
public static void setAdapter(Class<? extends Adapter> declaredAdapter){
staticAdapter = declaredAdapter;
}
public void talk(){
this.getAdaper().say();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment