Reputation: 31
I know what static is.. Globally.
So I was looking through a code, to get better in coding myself. I'm looking through the Minecraft source code, and for those who are interested to look there its in the files "TileEntity.java" and "EntityList.java". It is definitely not necessary to look over there, because its just a manner of programming.
So, we have just your regular class with a method:
public class EntityList{
public static void addMapping( /* variables that dont matter */ ){
//Call other methods, also unimportant
}
}
After that there is a class that imported EntityList
and does this:
import the.path.to.EntityList;
public class TileEntity{
static{
addMapping( /* vars */ );
addMapping( /* vars */ );
}
}
Now I'm wondering: How does this work? Please let me know if you need to know more background of the code, but I cannot redistribute the file due to copyright and stuff. Then you have to decompile Minecraft if you have it yourself.
Upvotes: 2
Views: 129
Reputation: 692063
We can't see the real code, but my guess is that it contains a static import:
import static the.path.to.EntityList.addMapping;
or
import static the.path.to.EntityList.*;
A static import allows referring to a static field or method of a class without having to type the name of the class.
See http://docs.oracle.com/javase/1.5.0/docs/guide/language/static-import.html for more details.
Upvotes: 3