Use typical param shadow reference types? (Java)
Let's say we have the following scenario:
public class SomeClass {
}
And now we have a generic class with a 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 be a SomeClass
shadow reference data type SomeClass
in general GenericClass
?
Yes . This is the name of the shadow in this context. You can still disambiguate the fully qualified class name (if you use the package as you would expect). It is also a good argument for using normal short type names for your generic types.
In a word - yes, there will be a shadow SomeClass
. You can still use the fully qualified class name (for example com.exmaple.SomeClass
) to refer to it.