Skip to content

Instantly share code, notes, and snippets.

@ypetya
Last active August 29, 2015 14:01
Show Gist options
  • Select an option

  • Save ypetya/3b2ebfcd7a56df527ed3 to your computer and use it in GitHub Desktop.

Select an option

Save ypetya/3b2ebfcd7a56df527ed3 to your computer and use it in GitHub Desktop.
PECS example
public static void getOldSeaAnimals(List<? extends SeaAnimal> animals, List<? super SeaAnimal> oldAnimals)
{
for (SeaAnimal animal:animals)
{
if (animal.getAge() > 100)
{
oldAnimals.add(animal);
}
}
}
public static void exampleCalls() {
List<SeaAnimal> input1 = new ArrayList<SeaAnimal>();
List<Animal> output1 = new ArrayList<Animal>();
input1.add(new Fish(200));
input1.add(new Fish(150));
input1.add(new Fish(300));
AnimalUtils.getOldSeaAnimals(input1, output1);
List<Fish> input2 = new ArrayList<Fish>();
List<SeaAnimal> output2 = new ArrayList<SeaAnimal>();
input2.add(new Fish(200));
input2.add(new Fish(150));
input2.add(new Fish(300));
AnimalUtils.getOldSeaAnimals(input2, output2);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment