google / google/error-prone

Public constructor on an abstract class

Open
#134 1 comment 1 reaction 0 assignees View on GitHub
migrated Priority-Medium Type-NewCheck
Dominant language
Java
Stars
7.2k
Forks
820
Avg merge
5h 9m
Merged PRs (30d)
50

Description

_[Original issue](https://code.google.com/p/error-prone/issues/detail?id=134) created by **dovwas@google.com** on 2013-06-05 at 02:25 PM_

---

A constructor on an abstract class should be declared as protected, there is never a need to declare it as public, since only subclasses can actually invoke it. There is, admittedly, not much negative consequence for this error, but I feel it is always a mistake, and one I'd be happy to see my compiler warn me about.
# Positive case:

public abstract class AbstractReport {

  public AbstractReport(String reportName) {
    // ...
  }

  public abstract void runReport();

}
# Negative case:

public abstract class AbstractReport {

  protected AbstractReport(String reportName) {
    // ...
  }

  public abstract void runReport();

}

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.