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.
Gleefully, I implemented the code thusly:
public class Order {
static int totalOrdersPlaced;
public int orderID;
public void Order() {
totalOrdersPlaced++;
orderID = totalOrdersPlaced;
}
}
...which throws a "cannot make a static reference to the non-static field" error for reasons I roughly understand. But I can't quite figure out how to implement what I want.
tl;dr: How to I make the program get the current value of a static variable and store it?