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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T01:38:03+00:00 2026-05-19T01:38:03+00:00

I am going through Effective Java and some of my things which I consider

  • 0

I am going through Effective Java and some of my things which I consider as standard are not suggested by the book, for instance creation of object, I was under the impression that constructors are the best way of doing it and books says we should make use of static factory methods, I am not able to few some advantages and so disadvantages and so am asking this question, here are the benefits of using it.

Advantages:

  1. One advantage of static factory methods is that, unlike constructors, they
    have names.
  2. A second advantage of static factory methods is that, unlike constructors,
    they are not required to create a new object each time they’re invoked.
  3. A third advantage of static factory methods is that, unlike constructors,
    they can return an object of any subtype of their return type.
  4. A fourth advantage of static factory methods is that they reduce the verbosity
    of creating parameterized type instances.

Disadvantages:

  1. The main disadvantage of providing only static factory methods is that
    classes without public or protected constructors cannot be subclassed.
  2. A second disadvantage of static factory methods is that they are not
    readily distinguishable from other static methods.

Reference: Effective Java, Joshua Bloch, Edition 2, pg: 5-10

I am not able to understand the fourth advantage and the second disadvantage and would appreciate if someone can explain those points. I would also like to understand how to decide to use whether to go for Constructor or Static Factory Method for Object Creation.

  • 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-19T01:38:04+00:00Added an answer on May 19, 2026 at 1:38 am
    • Advantage 4: When using a constructor, you have

      Foo<Map<Key, Value>> foo = new Foo<Map<Key, Value>>();
      

      vs

      Foo<Map<Key, Value>> foo = Foo.createFoo(); // no need to repeat
      

      this advantage will be gone in Java 7, when the diamond syntax will be introduced

    • Disadvantage 2. You can’t easily tell whether a given static method is used for constructor, or for something else.

    As for how to choose – there is no single recipe for that. You can weigh all of the above advantages and disadvantages given a use-case, but most often it will just be a decision driven by experience.

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

Sidebar

Related Questions

After going through the Appendix A, C# Coding Style Conventions of the great book
I was going through the AWDR book on web development with ruby on rails
I was going through some code and came across a scenario where my combobox
I'm going through some old stored procedures at work and constantly come across CASE
I am going through some pl/sql code with no comments. Trying to make sense
So I've been reading Effective Java by Joshua Bloch and noticed two points which
Going through the Game Center / GameKit docs, I could not find any information
While going through university and from following the development of SO, I've heard a
I'm going through the problems on projecteuler.net to learn how to program in Erlang,
We're going through a massive migration project at the minute and trying to validate

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.