Simple Question

Discussion in 'Plugin Development' started by dotJar1, Oct 9, 2016.

Thread Status:
Not open for further replies.
  1. Offline

    dotJar1

    So I have been taking learning java very slowly for the past 7 weeks, and I have been watching thenewbostons tutorials along with reading a few books. In both the book and the newboston tutorials, they say that they will explain what static means later. I dont know if they do eventually explain it, but I want to know as soon as I can, what does static mean?
     
  2. Zombie_Striker likes this.
  3. Offline

    Zombie_Striker

    @dotJar1
    In short, static objects are objects that are the same for all instance of the same class. So for example, lets say I had the following class
    Code:
    public class Class{
    
    public static Object anything = new Ojbect();
    
    public boolean areTheSame(){
    
    return new Class().anything == this.anything;
    }
    
    
    }
    What this does is create a new object for all instances for "class". The method "areTheSame" is meant to prove that the "anything" is exactly the same for all instance of "Class".

    Some other things about static objects are that they don't get cleaned by the JGC (Java garbage collector), meaning you have to remember to manually set each value to null if you don't want to waste memory (especially for Bukkit, since reloads don't handle static objects.).
     
    Last edited: Oct 10, 2016
  4. ;)
     
    Zombie_Striker likes this.
Thread Status:
Not open for further replies.

Share This Page