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

  • Home
  • SEARCH
  • 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 8862473
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T15:44:15+00:00 2026-06-14T15:44:15+00:00

Okay, so as far as I know, I understand these things about a final

  • 0

Okay, so as far as I know, I understand these things about a final variable.

  1. It should be assigned only once
  2. All the final variables should be initialized before the constructor completes

Now using the above, I do not understand how the below doesn’t work:

public class FinalTest implements AnotherClass {

    private final Something something;
    private final otherthing;

    @Override
    public void setStuff(Something something) {
        this.something = something;
        this.otherthing = new SomeClass(something);
    }

    public FinalTest(Something something) {
        setStuff(something);
    }
}

Here, before the constructor completes the final variables are being set. So why does the compiler complain against it?

  • 1 1 Answer
  • 0 Views
  • 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-06-14T15:44:16+00:00Added an answer on June 14, 2026 at 3:44 pm

    It’s not necessary that your method gets called only from constructor, it can be called from outside your constructor also. And even a second call might be added to the same constructor in future also.

    Even though you might not have used it now, but Compiler cannot be sure about it, so it does not allow it. In technical term, there is no definite assignment.

    For e.g: – suppose you instantiate your class from main: –

    public static void main(String[] args) {
        FinalTest obj = new FinalTest(something);
    
        obj.setStuff(something); // There you go. This cannot be prevented. 
    }
    

    See JLS – Definite Assignments for detailed explanation on this.

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

Sidebar

Related Questions

Okay, I know this is a common enough question, but all the solutions I've
Okay I kind of know how to display the time with PHP and MySQL
Okay, I really know this has GOT to be the long way around doing
I know that using scriptlets are considered taboo nowadays. Its okay and I will
Okay, I've set up a bit of code which searching for all the pages
I know LINQ but my knowledge is pretty much only selects, where, orderby and
I know this is crazy, but IE can drive one to do crazy things.
Okay so i'm trying to convert a couple things. So i have already converted
Okay, I know that is a funky-sounding title, but I couldn't think of a
Okay, I get it. Data in PostgreSQL is case-sensitive. And I know I can

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.