Let's say we have the following scenario:
public class SomeClass {
}
And now we have a generic class with type parameter SomeClass
instead of T
.
public class GenericClass <SomeClass> {
List<SomeClass> list;
public GenericClass() {
list = new ArrayList<>();
}
public void add(SomeClass obj) {
list.add(obj);
}
}
Will the type parameter SomeClass
shadow the reference datatype SomeClass
in the whole GenericClass
?
Yes. That's a name shadow in this context. You can still disambiguate with the fully qualified class name (as long you as you use a package, as you should). Also, this is a good argument for using conventional short type names for your generic types.