title: Java: getting the current value of a static variable
body: <p>I'm trying to create a bunch of objects with unique IDs. My first idea for implementing this was to have a static variable that counted the amount of objects. Each time an object is created, the static variable is increased by one and written down as the ID of the object.</p>
  
  <p>Gleefully, I implemented the code thusly:</p>
  
  <pre><code>    public class Order {
          static int totalOrdersPlaced;
          public int orderID;
  
          public void Order() {
              totalOrdersPlaced++;
              orderID = totalOrdersPlaced;
          }
      }
  </code></pre>
  
  <p>...which throws a "cannot make a static reference to the non-static field" error for reasons I <em>roughly</em> understand. But I can't quite figure out how to implement what I want.</p>
  
  <p>tl;dr: How to I make the program get the current value of a static variable and store it?</p>