I am trying to conditionally create a Generic instance in Java where the type is passed as a parameter. Something like that:
private void doStuff(somethingThatDescribesWhatTShouldBeHere) {
ArrayList<thetypeTthatwaspassedin> = new ArrayList<thetypeTthatwaspassedin>
... rest of logic
}
I can’t understand what life a T-parameter should look like without ArrayList<T>screaming towards me.
The idea is that Tthis is a string, then an instance is created ArrayList<String>.. if it is Foo, then an instance is created instead ArrayList<Foo>.
Please, help
source
share