I have an abstract class. I want that every instance has a unique ID. I have implemented:
public abstract class MyAbstractClass{
static AtomicInteger nextId = new AtomicInteger();
private int id;
public MyAbstractClass() {
id = nextId.incrementAndGet();
}
}
public class MyClass extends MyAbstractClass {
public MyClass(){
super();
}
}
This approach works except the part there is nothing forcing the subclass to call the constructor.
Is there a way to implement a global ID for an abstract class?