I have a class called Foo which in some of its methods relies on a value globalTime that depends on time. To simplify it let's say it's a long integer storing the number of seconds since the program started. Now, I want all the instances of Foo to share the exact same value for globalTime. I, of course could create another class which stores the value and make all the instances of Foo retrieve the value for that class but I was just wondering: Is there a way I could do this from within the class?
I'm looking for something like an static field but being able to change its value, although it's stored only once, not once for every instance, and thus every instance from that class would share the same value for that field.
I'm just curious about whether something like this exists in Java, I'm not saying it's a better or worse practice than any other alternative, so please do not discuss the "purpose" of wanting to do this.