After I use IntelliJ to inspect my code, hundreds of "Declaration can have final modifier" warnings are issued. To resolve these warnings, I essentially need to turn most of my variables into final, and the following is one typical example. This provokes me to think that I should make member variables as 'final' by default. In most cases, members, especially container classes (i.e. List or Set) ,won't get changed once they are assigned. They change internally by inserting or removing elements from them, but the references to them won't change.
public class Attribute {
private final Insight insight;
private final Attribute attribute;
private final List<String> names;
public Attribute(Insight insight, Attribute attribute) {
attribute = attribute;
insight = insight;
names = new ArrayList<>();
}
}
Does it make sense to make most variables as final by default in design classes? Is it the case that most member variables can be defined as 'final' in Java?