compilation fails with 'no enclosing instance' error
Alex Buckley
alex.buckley at oracle.com
Thu Feb 13 16:26:45 PST 2014
Filed https://bugs.openjdk.java.net/browse/JDK-8034924.
Some observations:
- The compile-time error appears (incorrectly) whether the static method
in base.BaseImpl is package access or private. But if the static method
is public, then everything works fine: Impl.foo(Object) attempts to
override base.BaseImpl.foo(Object), and a compile-time error occurs
because an instance method cannot override a static method.
- In MyImpl.m, if you replace foo(o) with this.foo(o), then the program
compiles correctly.
Alex
On 2/13/2014 2:51 PM, Liam Miller-Cushon wrote:
> Thanks for confirming.
>
> Would someone with access to the bug tracker mind filing this? Or should
> I submit a report to http://bugreport.java.com? It would be helpful to
> have a bug ID to refer to.
>
>
> On Wed, Feb 12, 2014 at 6:20 PM, Alex Buckley <alex.buckley at oracle.com
> <mailto:alex.buckley at oracle.com>> wrote:
>
> Regression. MyImpl inherits the instance method foo(Object) from
> Impl, and foo(o) should invoke the inherited method. At least javac
> is recognizing that the type Impl is an important source of truth.
>
> The foo(Object) method in base.BaseImpl is irrelevant because,
> having package access, it's not inherited by Impl.
>
> Alex
>
>
> On 2/12/2014 5:49 PM, Liam Miller-Cushon wrote:
>
> Hi,
>
> I discovered a JDK8-b128 compilation error that does not occur
> with JDK7:
>
> === base/BaseImpl.java ===
> package base;
>
> public class BaseImpl {
> static void foo(Object o) {}
> }
> ===
>
> === Test.java ===
> class Impl extends base.BaseImpl {
> public void foo(Object o) {}
> }
>
> class MyImpl extends Impl {
> public void m(Object o) {
> foo(o);
> }
> }
> ===
>
> $ javac base/BaseImpl.java Test.java
> Test.java:7: error: no enclosing instance of type Impl is in scope
> foo(o);
> ^
>
> Is this a deliberate change, or a regression? If it's
> deliberate, the
> error message is not very clear.
>
>
More information about the compiler-dev
mailing list