Skip to main content

Questions tagged [final]

The tag has no usage guidance.

-4 votes
2 answers
115 views

In java string classes are final, than how did we enter value on string even its a final class?

In Java string classes are final, we know that we can't inherit a final class and not able to write on this, then how did we enter a value on a string even its a final class?
md mohiuddin's user avatar
12 votes
3 answers
3k views

What are the pros and cons of using final methods (in abstract classes)

For the purpose of writing a coding styleguide, how should final methods in software design be judged? By final I mean the Object-oriented sense that a class that can be subclassed provides methods, ...
tkruse's user avatar
  • 274
3 votes
2 answers
238 views

Explicit type and final in stream lambdas

This argument has been going on for weeks: Bot.getGuild().getMembers().stream() .filter((final Member m) -> m.getRoles().size() == 0) .filter((final Member m) -> !m.getUser()....
Julian Durchholz's user avatar
0 votes
0 answers
72 views

Is making method parameters final a worthy endeavour? [duplicate]

It is generally a good idea to restrict access to your variables as much as reasonably possible. For example make things private instead of publicand make variables final if they aren't supposed to ...
David says Reinstate Monica's user avatar
55 votes
10 answers
18k views

Why would the 'final' keyword ever be useful?

It seems Java has had the power to declare classes not-derivable for ages, and now C++ has it too. However, in the light of the Open/Close principle in SOLID, why would that be useful? To me, the ...
Vorac's user avatar
  • 7,129
17 votes
3 answers
8k 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 method....
dmytroy's user avatar
  • 283
4 votes
2 answers
3k 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 ...
Unknown Id's user avatar
0 votes
2 answers
525 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 ...
overexchange's user avatar
  • 2,285
17 votes
2 answers
4k 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() { ...
Jake Anderson's user avatar
2 votes
1 answer
3k 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 can'...
Ky -'s user avatar
  • 545
33 votes
2 answers
55k 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 ...
Alex Wolf's user avatar
  • 441
8 votes
2 answers
17k 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 errors.rejectValue("...
happybuddha's user avatar
1 vote
2 answers
976 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 ...
Rushi Shah's user avatar
2 votes
1 answer
5k 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 ...
leseulsteve's user avatar
4 votes
3 answers
3k 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, ...
oberlies's user avatar
  • 466

15 30 50 per page