I was poking through the source code for a neat little application and saw this bit of syntax:
public class TerrainEditor{
//constructor
public void makeBlock(Vector3Int pos, Class <? extends Block> block) {
//creates the block
}
//other code
}
No, it wasn’t Minecraft by the way.
The bit that confused me was the Class <? extends Block> block. From what I have seen, to use this method you would have to provide something like
editor.makeBlock(/*pos*/, BlockWood.class);
Correct?
If so, what is the point of this? I suppose so that you don’t have to instantiate a new object of the class. What does one do with this object though, is it purely for calling static values or something?
It seems like an interesting little piece of Java, I’d like to use it later because if it is what I am thinking it is, it’s very useful.
Thanks.
Edit:
Just realized I have seen things similar to this before:
public void method(Class<Object> object){
//stuff
}
I suppose these are related, however I do not know the difference between the one with the ‘?’ and the one w/o. Mind explaining?