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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T07:31:17+00:00 2026-06-13T07:31:17+00:00

Possible Duplicate: Consider providing static factory methods insteads of constructors This maybe a controversial

  • 0

Possible Duplicate:
Consider providing static factory methods insteads of constructors

This maybe a controversial question and may not be suited for this forum (so I will not be insulted if you choose to close this question).

It seems given the current capabilities of Java there is no reason to make constructors public … ever. Friendly, private, protected are OK but public no.

It seems that its almost always a better idea to provide a public static method for creating objects. Every Java Bean serialization technology (JAXB, Jackson, Spring etc…) can call a protected or private no-arg constructor.

My questions are:

  • I have never seen this practice decreed or written down anywhere? Maybe Bloch mentions it but I don’t own is book.
  • Is there a use case other than perhaps not being super DRY that I missed?

EDIT: I explain why static methods are better.

.1. For one you get better type inference. For example See Guava’s http://code.google.com/p/guava-libraries/wiki/CollectionUtilitiesExplained

.2. As a designer of the class you can later change what is returned with a static method.

.3. Dealing with constructor inheritance is painful especially if you have to pre-calculate something.
.4. More reasons here: https://stackoverflow.com/a/3852556/318174

I should have posted that this is for public API like code. I frequently violate all sorts of rules (like using direct field access) for Unit Testing, convenience, and cause I’m lazy. So when I meant ever, I meant your releasing it into the wild.

  • 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-13T07:31:18+00:00Added an answer on June 13, 2026 at 7:31 am

    If following is how the method looks

    public class MyClass {
    
        private MyClass() { }
    
        public static MyClass getInstance() {
            return new MyClass();
        }
    }
    

    then would prefer to have a public no-arg constructor.

    If I have to call some method like that, it will make me feel that it is doing something to construct the object but in reality it isn’t.

    I don’t think there is any point in having a method that doesn’t do anything but invoke the constructor itself.

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

Sidebar

Related Questions

Possible Duplicate: No type inference with generic extension method Consider two methods: public static
Possible Duplicate: Why copy constructor is not called in this case? Consider the sample
Possible Duplicate: Is short-circuiting boolean operators mandated in C/C++? And evaluation order? Consider this
Possible Duplicate: Static Initialization Blocks Consider the following code : public class Test {
Possible Duplicate: Jquery: Selection within a selection Consider this code: var $el = $('<div
Possible Duplicate: Is there a CSS parent selector? Consider this markup: <div> <div> <p
Possible Duplicate: Reference - What does this symbol mean in PHP? Consider this code
Possible Duplicate: Calculate a Running Total in SqlServer Consider this data Day | OrderCount
Possible Duplicate: Who calls the main function in java? Consider this code: class abc
Possible Duplicate: Java Thread Garbage collected or not Consider the following class: class Foo

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.