public class Test {
private static int counter = 1;
int uniqueId;
public Test() {
uniqueId = counter++;
}
public int getUniqueId() {
return uniqueId;
}
}
public class TestSub {
public static void main(String args[]) {
Test a = new Test();
Test b = new Test();
}
}
Asked
Active
Viewed 37 times
0
-
My mistake. I misread the question – Hovercraft Full Of Eels Oct 19 '19 at 18:39
-
@HovercraftFullOfEels : My question is that is there any design fault by using this approach? – Naresh Oct 19 '19 at 19:07
1 Answers
0
Assuming that:
the scope of int is large enough for your needs
you will not work with more than one thread at a time
you do not need randomness (for security reasons)
it should do exactly what you're describing.

Czarnowr
- 83
- 5