Skip to content

Instantly share code, notes, and snippets.

@soc
Created August 1, 2012 17:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save soc/3229086 to your computer and use it in GitHub Desktop.
Save soc/3229086 to your computer and use it in GitHub Desktop.
package zoo;
class Animal {}
class Lion extends Animal {}
class Cage<T extends Animal> {
void add(T animal) { System.out.println("Adding animal..."); }
public static void main(String... args) {
Cage<? extends Animal> animals = null;
Cage<Lion> lions = null;
animals = lions;
animals.add(new Lion()); //ERROR
}
}
/*
The method add(capture#2-of ? extends Animal) in the type Cage is not applicable to for the arguments (Lion)
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment