Guest User

Untitled

a guest
Oct 18th, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.58 KB | None | 0 0
  1. public class CardFactory<Type extends Card> {
  2.  
  3. private final Class<Type> cardType;
  4. private CardInfo info;
  5.  
  6. public CardFactory(final Class<Type> cardType) {
  7. this.cardType = cardType;
  8. }
  9.  
  10. public void setCardInfo(CardInfo info) {
  11. this.info = info;
  12. }
  13.  
  14. public Type create() throws InstantiationException, IllegalAccessException,
  15. NoSuchMethodException, InvocationTargetException {
  16. Constructor<Type> constr = cardType.getConstructor(CardInfo.class);
  17. Type card = constr.newInstance(this.info);
  18. return card;
  19. }
  20. }
Add Comment
Please, Sign In to add comment