How to create a variable that can be set only once but isn’t final in Java
Let me suggest you a little bit more elegant decision. First variant (without throwing an exception): public class Example { private Long id; // Constructors and other variables and methods deleted for clarity public long getId() { return id; } public void setId(long id) { this.id = this.id == null ? id : this.id; } … Read more