HackerTrans
TopNewTrendsCommentsPastAskShowJobs

petrigun

no profile record

comments

petrigun
·5 anni fa·discuss
OP said that we would have to use reflection to make this work in Java, but I think we can also make use of Generic classes:

  class Pokemon<T extends PokeType> {
    public T type;

    public Pokemon(T givenType) {
      type = givenType;
    }
  }
and in main():

  Normal n1 = new Normal();
  Pokemon<Normal> pokemon1 = new Pokemon<>(n1);