While learning Java generics I came to know that with covariance we can read items from a structure, but we cannot write anything into it and with contravariance we can write items into a structure, but we cannot read anything from it.
Let's take an example :
List<? extends Number> myNums = new ArrayList<Integer>();
myNums.add(45L); // Covariance - compiler error
List<? super Integer> myNums = new ArrayList<Integer>();
myNums.add(1);
Number myNum = myNums.get(0); //Contravariance - compiler-error
What I am not able to understand is why is this thing prohibited ? I am not able to understand what can go wrong if this thing is allowed to happen ?