In java I sometimes use class variables to assign an unique id to each new instances. I do something like:
public class Foo {
private static long nextId = 0;
public final long id;
public Foo() {
id = nextId;
nextId++;
}
[...]
}
How can I reproduce this behaviour in scala ?