Edit: Sorry for my previous question, the final keyword will confusing you, It's not appropriate. And sorry for my poor English too.
-----Question------
Assume I have a model class without any constructor, because I need to initialize it within many different logic. But i have a notnull keyword.
public class Model { public notnull String name; public notnull String address; public notnull int age; } And I need to use it in different place but keep checking if all notnull fields were initialized in compile time
Model m = new Model(); m.name = "Hello"; m.age = 15; // syntax error, you should set Model.address Or
Model m1 = new Model(); m1.address = "World"; m1.age = 20; // syntax error, you should set Model.name How can I achieve that in java? Thx.
final String a = "A", in EACH constructor asa = "A"or within an instance initializer block as{ a = "A" }, otherwise you get a compile time error. The way you do currently have it set up thefinalwouldn´t make sense as you are not in need to initialize them which would contradict what thefinalis there for.notNullor something similar in java. The most similar you can have is thefinal, which dooms you to initialize, wherenullisn´t forbidden...