0
private static void printNumbers(List<? extends Number> numbers) {
    Number number = numbers.get(0);
}

or

List<String> names = new ArrayList<>();
List<?> tmp = names;

i learn the wildcard, use '?' symbol. and i learn this is also wildcard.

in my Thinking 'E' is not '?' symbol even though it works like upper bound wildcard. and if were E is wirdcard, how can i distingush between parametered type and wildcard type.

public class Cage<E extends Animal> {
    private E animal1;
    private E animal2;

    public Cage() {
    }
    public Cage(E animal1, E animal2) {
        this.animal1 = animal1; this.animal2 = animal2;
    }

    public E getAnimal1(){
        return animal1;
    }
    public boolean isCompatible() {
        return animal1.getType == animal2.getType;
    }
}
public class Animal {
    private String type;
    public String getType() {
        return type;
    }
    public void setType(String type) {
        this.type = type;
    }
}
public class Monkey extends Animal {
}
public class Lion extends Animal {
}
chobodark
  • 25
  • 4
  • "*How*" is but the form, following the function of "*Why*". The question sounds very much like a [XY problem (`meta.stackexchange.com`)](https://meta.stackexchange.com/questions/66377/what-is-the-xy-problem). The wildcard bound is mostly used in conjunction with the [PECS mnemonic (`stackoverflow.com`)](https://stackoverflow.com/questions/2723397/what-is-pecs-producer-extends-consumer-super), not in generic classes themselves. – Turing85 Jul 23 '23 at 17:08
  • Start by looking at the official explanation of how generics works [over on the official Java website](https://www.oracle.com/technical-resources/articles/java/juneau-generics.html), because it sounds like you've not done your [prerequisite (re)searching](/help/how-to-ask) before posting. – Mike 'Pomax' Kamermans Jul 23 '23 at 17:08

0 Answers0