Type variable hides another type¶
Type shadowing occurs if two types have the same name but one is defined within the scope of the other. This can arise if you introduce a type variable with the same name as an imported class.
Type shadowing may cause the two types to be confused, which can lead to various problems.
Name the type variable so that its name does not clash with the imported class.
In the following example, the type
java.util.Map.Entry is imported at the top of the file, but the class
Mapping is defined with two type variables,
Entry. Uses of
Entry within the
Mapping class refer to the type variable, and not the imported interface. The type variable therefore shadows
class Mapping<Key, Entry> // The type variable 'Entry' shadows the imported interface 'Entry'.
To fix the code, the type variable
Entry on line 4 should be renamed.