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 7671407
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T16:02:52+00:00 2026-05-31T16:02:52+00:00

Stylistically is it better to initialise Java fields within a constructor or at the

  • 0

Stylistically is it better to initialise Java fields within a constructor or at the point where the field is declared? For example:

public class Foo {
  private final List<String> l;

  public Foo() {
    this.l = new LinkedList<String>();
  }
}

… or

public class Foo {
  private final List<String> l = new LinkedList<String>();
}

I have typically favoured the former as it seemed clearer. However, the latter obviously results in more compact code.

  • 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-05-31T16:02:53+00:00Added an answer on May 31, 2026 at 4:02 pm

    My rule of thumb is:

    Put it at the point of the declaration if

    • …it can (i.e. if it doesn’t rely on constructor arguments for instance)
    • …it’s value does not need any form of computation
    • …the value is the same regardless which constructor is used.

    otherwise, put it in the constructor.

    Usually I follow the official Java Coding Conventions strictly. In this particular case the convention doesn’t say anything about it, so it’s up to each programmer to decide. Which ever you pick however, you probably want to be consistent with your choice.

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

Sidebar

Related Questions

Public Class FooBar { private int _foo; public int Foo { get { return
I've recently made a change stylistically and wanted to see how other c++ programmers
I am using codeigniter's session class to handle my PHP sessions. One of the
I'm asking in both contexts: technically and stylistically. Can my application/daemon keep a pidfile
Here is the markup I'm using: <ul class=menu> <li id=planning_menuItem class=menuItem><a href=/estate_planning/ title=Estate Planning>Estate
I want to calculate the average of a set of circular data. For example,
I need to deal with a two objects of a class in a way
Sometimes I find myself creating a CSS class for a single element. So instead,
Im implementing ITU standard based loudness measurement program and as it states i should
long shot question here! My chart has 3 views, in one of the views

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.