Use of generics and sub-typing in Java