Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8191896

confusing applicability error

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: P4 P4
    • tbd
    • None
    • tools
    • None

      // base/Base.java
      package base;
      public class Base {
          Base(String value) { }
      }

      // Derived.java
      import base.Base;
      public class Derived extends Base { }

      javac 9.0.1 produces the following:

      src/Derived.java:2: error: constructor Base in class Base cannot be applied to given types;

      public class Derived extends Base { }

             ^

        required: String

        found: no arguments

        reason: actual and formal argument lists differ in length

      This is misleading because it implies that by adding a Derived constructor to call Base(String), that the error can be fixed; however, doing so results in a compiler.err.report.access error because the Base(String) constructor is not accessible:

      src/Derived.java:4: error: Base(String) is not public in Base; cannot be accessed from outside package

              super(value);

              ^

            vromero Vicente Arturo Romero Zaldivar
            mcimadamore Maurizio Cimadamore
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: