The tag has no wiki summary.

learn more… | top users | synonyms

3
votes
2answers
109 views

In C++, when should I use final in virtual method declaration?

I know that final keyword is used to prevent virtual method from being overriden by derived classes. However, I can't find any useful example when I should really use final keyword with virtual ...
2
votes
2answers
171 views

Java: using final keyword only on method parameters that expect immutable objects? [closed]

I came across the interesting topic about final method parameters and that they essentially don't provide much advantages. I wondered if it would be sensible to mark only those method parameters as ...
0
votes
2answers
196 views

Why 'class String' definition has 'final' modifier? [duplicate]

This answer gives an indication that class String is declared final for thread safety, which does not convince. This answer does not convince when it says: And so, you make the classes final. There ...
15
votes
2answers
2k views

Declaring a class final? [duplicate]

I like my code to be written well; however, I have run into not really an problem, but more of a question about conventions. Say I have this class. public class Test { public void doStuff() { ...
0
votes
1answer
251 views

When should a class be final? [duplicate]

I've only really seen this on Java's wrapper classes (String, Integer, etc.), but never in open-source projects, and I was never taught about it in any books or classes. I know it means the class ...
4
votes
1answer
2k 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
498 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
254 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
602 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 ...
3
votes
3answers
1k 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, ...
5
votes
1answer
248 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
2k 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 ...
43
votes
7answers
61k 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
4k 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 ...
43
votes
7answers
18k 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 ...
15
votes
4answers
6k 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 ...
35
votes
4answers
14k 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 ...