I feel like i have to ask this here because i can not find a proper answer somewhere else.
I'm trying to get this following code snippet to work where componentList is a List<Component>. I know some workarounds like the ones mentioned in the comments here. But i just wondered if theres is some kind of expression in java to check for an instanceof of an generic parameter without having an instance of it. I know i could also use an class or some kind of value as an identifier for it.
public <T extends Component> T getComponent(){
for (Component component:componentList) {
if(component instanceof T){
return component;
}
}
return null;
}
Already thank you for your answers and the spell checking^^