yegor256 / qulice

Quality Police for Java projects: aggregator of Checkstyle and PMD
https://www.qulice.com
Other
301 stars 112 forks source link

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

Closed yegor256 closed 4 months ago

yegor256 commented 7 months ago

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 commented 6 months ago

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

yegor256 commented 6 months ago

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

vladislav-yevtushenko commented 4 months ago

@yegor256 should it be closed?

yegor256 commented 4 months ago

@vladislav-yevtushenko yes, thanks!