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.
In a word - yes, it will shadow SomeClass. You could still use the fully qualified class name (e.g., com.exmaple.SomeClass) to reference it, though.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With