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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T13:58:08+00:00 2026-06-06T13:58:08+00:00

Say I have a class with three constructors, like the one below: public class

  • 0

Say I have a class with three constructors, like the one below:

public class ExampleClass {
    // constructor #1
    public ExampleClass(int a) {
        this(a, "aaa"); // "aaa" is just an arbitrary default for b
    }

    // constructor #2
    public ExampleClass(String b) {
        this(2, b); // 2 is just an arbitrary default for a
    }

    // constructor #3
    public ExampleClass(int a, String b) {
        // a has an arbitrary minimum value of 3
        // b has an arbitrary minimum length of 3
        if (a < 2 || b.length() < 2) {
            throw new IllegalArgumentException("a and b cannot be less than 2");
        }

        // ...
    }
}

In this case, I have three constructors. The third of which is sort of the primary constructor, the others simply provide defaults so the class can be constructed with only one value given instead of both. I’m attempting to write documentation for such classes via JavaDoc. If I were to write the documentation for either the first or second constructors, would I use the @throws tag to document the potential IllegalArgumentException? Or should I save documenting the IllegalArgumentException for the third constructor’s documentation only? In that case, what would be the best, most appropriate way of expressing that a must be above 2 or that b must be longer than 2 characters? How would I state that an IllegalArgumentException could be thrown without documenting it with @throws ?

  • 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-06T13:58:09+00:00Added an answer on June 6, 2026 at 1:58 pm

    All three of your constructors do throw an exception (you can verify this empirically) – you can’t expect a consumer of your code to know what goes on under the covers (ie whether the arguments are checked within the constructor, or by some method called by the constructor). As such, you should document all three constructors.

    It’s always nice to not repeat yourself, but not always practical – Javadoc can’t express the relationship you want, so you need to express it long hand.

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

Sidebar

Related Questions

say I have: class Test { public static int Hello = 5; } This
Say I have a class like this: class Person { private $value; public function
Say I have a class, something like the following; class MyClass { public: MyClass();
Let's say you have a class class C { int * i; public: C(int
In C#, if you have multiple constructors, you can do something like this: public
Lets say I have a test class called ServiceTest with three test methods test1,
let's say I have class Dummy { String a, b; public Dummy(String a, String
Lets say I have two similar class: public class First { public static final
I have this problem : when i call the Content class (the one who
I have seen examples containing things like this: mountSharedResource(/images/logo.gif, new ResourceReference(ImageScope.class, logo.gif).getSharedResourceKey()); mountSharedResource(/resource, Application.class.getName()

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.