1) You can see Carnivore type parameter is : E extends Animal
2) Now our case:
class Sheep extends Plant implements Carnivore<Wolf>
You can see here: Sheep extends Plant, so Sheep is a Plant now.
3) Now Wolf contract.
class Wolf extends Animal implements Carnivore<Sheep>
you can see here : Carnivore<Sheep> and Sheep is now Plant as in the case 2.
so it becomes Carnivore<Plant>.
Fine but case 1 contract says Carnivore should take Animal or subtype of Animal.
interface Carnivore<E extends Animal>
So this case is not possible, as it is breaking the contract of interface Carnivore<E extends Animal>
Given a method declared as
public static <E extends Number> List<E> process(List<E> nums)
// INSERT DECLARATIONS HERE
output = process(input);
they say that the following statement cannot be used,because The return type of process is definitely declared as a List, not an ArrayList
ArrayList<Integer> input = null;
ArrayList<Integer> output = null;
I thought, since ArrayList implements List,why cant we use this. isn't it something like List<Integer> fun= new ArrayList<Integer>();
Why to worry about things in which we dont have control, Why to worry about things in which we have control ! !