The tag has no wiki summary.

learn more… | top users | synonyms

0
votes
1answer
211 views

Naming convention: Final fields (not static)

Today I had a discussion with a co-worker about the naming of final fields in Java classes. In his opionion final fields should also be considered constants since their values won't change after the ...
3
votes
2answers
313 views

Why to declare a String (as final) and then use it?

In a typical spring mvc validator class, while inserting an errorCode value in the Errors object, what difference does it make between using a String (props.somefield.req) like so ...
1
vote
2answers
189 views

What's the difference of an object being final and an object being immutable in java?

final String str = "do not change me"; str = "why not?"; //it will result in compile time error saying that final fields can not be re-assigned once created i.e. the reference cannot be changed ...
1
vote
1answer
223 views

inheritance and static final variables

I'm a programing student. I've been having problem to organize Java classes that use inheritance and static final variables. Let say I have an abstract class named Form that has two children named ...
0
votes
3answers
549 views

Java: How to make local fields & parameters final without having a 'final' keyword on each declaration

By default, I want all my local variables and method parameters to be final. Unfortunately, the Java language designers chose a different default: variables&parameters are by default non-final, ...
6
votes
1answer
242 views

Declaring functions as final… except when it is me who does the deriving

I have a class in which I want to disallow other programmers from overriding one of it's methods, since it requires special knowledge of the inner workings of the class. Since I personally know how ...
3
votes
4answers
959 views

Immutable Method in Java

In Java, there is the final keyword in lieu of the const keyword in C and C++. In the latter languages there are mutable and immutable methods such as stated in the answer by Johannes Schaub - litb ...
37
votes
7answers
37k views

Why declare final variables inside methods? [duplicate]

Studying some classes of Android, I realized that most of the variables of methods are declared as final. Example code taken from the class android.widget.ListView: /** * @return Whether the list ...
13
votes
7answers
3k views

Why is the 'final' keyword used so little in the industry? [closed]

Since I discovered the powers of the final keyword in Java a few years ago, it helped me to make my codes a lot more readable, since people can easily see what are read-only variables. It may also ...
38
votes
7answers
10k views

Excessive use “final” keyword in Java [duplicate]

While I understand what the final keyword is used for in the context of classes and methods as well as the intent of its use for in regards to variables; however, the project I just started working on ...
7
votes
5answers
3k views

Why is using 'final' on a class really so bad?

I am refactoring a PHP OOP legacy website. I am so tempted to start using 'final' on classes to "make it explicit that the class is currently not extended by anything". This might save lots of time ...
26
votes
4answers
8k views

In Java, should I use “final” for parameters and locals even when I don't have to?

Java allows marking variables (fields / locals / parameters) as final, to prevent re-assigning into them. I find it very useful with fields, as it helps me quickly see whether some attributes - or an ...