Created
May 2, 2015 15:17
-
-
Save tamoot/a84e2e6bae67c2f74c3f to your computer and use it in GitHub Desktop.
素人がGenericsを使おうとしたさんぷる
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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