Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

prohibit private constructors if they are not used in the class #1258

Open
yegor256 opened this issue Apr 16, 2024 · 2 comments
Open

prohibit private constructors if they are not used in the class #1258

yegor256 opened this issue Apr 16, 2024 · 2 comments

Comments

@yegor256
Copy link
Owner

yegor256 commented Apr 16, 2024

This code should be illegal:

class Foo {
  String s;
  public Foo(String s) {
    this.s = s;
  }
  private Foo(int x) { // this is wrong!
    // ...
  }
}

Instead, this private constructor should be public or protected or package visible.

@pnatashap
Copy link
Contributor

@yegor256 are you sure about the example? this(1); should call private ctor in this case

@yegor256
Copy link
Owner Author

@pnatashap you are right, my mistake, I updated the example above

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants