3 ms·
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
by petrigun 5y ago
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);