Unable to override method due to name clash

This code does not compile:

import java.util.List; class A { void foo(List l) { } } class B extends A { void foo(List<?> l) { } } 

However, the following code compiles (foo in D overrides foo to C). Why?

 class C { void foo(List<?> l) { } } class D extends C { void foo(List l) { } } 
+4
source share
1 answer

The second example compiles because List <> comes from a list, but not vice versa, why the first example does not compile.

+2
source

Source: https://habr.com/ru/post/1410991/


All Articles