Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6187851
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T02:07:48+00:00 2026-05-24T02:07:48+00:00

I was looking at some code from a colleague and saw the following method:

  • 0

I was looking at some code from a colleague and saw the following method:

public void someMethod(final String str) {
    ...
}

which I found odd, as Strings are immutable, anyway. I think it is safe to delete the final keyword, there.

I also found the following

public void reportProblems(final Collection<IProblem> problems) {
    ...
}

There aren’t any inner classes around, so.. is there a point in using the final keyword there? It looks to me that having the final there is absolutely the same as not having. Am I right?

Thanks

  • 1 1 Answer
  • 1 View
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T02:07:49+00:00Added an answer on May 24, 2026 at 2:07 am

    The immutability of string is completely irrelevant to whether it’s declared final or not. You could have a final StringBuilder parameter, and it would prevent exactly the same thing: reassignment of the variable within the method. You’d still be able to append to the StringBuilder. final in Java isn’t the same as const in C++.

    Some people like to make everything final when they can – if you know that the value of a variable doesn’t change, it can be easier to reason about it. I have a lot of sympathy with that view, and often take the same approach myself – except that I don’t actually force the issue with the final modifier, simply because it adds cruft in the code. If final were the default and you had to explicitly use a mutable modifier, I suspect that most developers wouldn’t start making every local variable mutable… they’d just use the default most of the time, as they do now.

    So, to come back to the original question: I suspect the developer just wants to be explicit about their style. It’s not how I do it, but I can understand the motivation. Another possibility is that at one point there was an inner class, but that’s gone now and the developer forgot to remove the final modifier.

    Of course, if your colleague wrote the code, you don’t have to guess – just ask!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm looking at some iOS sample code from Apple which shows off GLES2 functionality,
I am currently looking at some code which basically reads data line-by-line from a
I am looking though some source code from a third party and am repeatedly
Today I was looking at some code atually from Nikhil Kothari's Facebook.NET API. I
I was looking into using some .NET code from within a Delphi program, I
Looking through some code I came across the following code trTuDocPackTypdBd.update(TrTuDocPackTypeDto.class.cast(packDto)); and I'd like
I'm looking at some code which should be trivial -- but my math is
I am looking at some code (Delphi 7) with following check is at the
I was looking at some code from a tutorial for creating a carousel menu
So I'm looking at some code from Eloquent Javascript and it says that to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.