Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Method does not override package visible method in Eclipse

From the Eclipse Java compiler setting: Method does not override package visible method

"A package default method is not visible in a different package, and thus cannot be overridden. When this option is enabled, the compiler will signal such scenario either as an error or a warning."

How can I trigger this Warning/Error? I'm looking for a code example.

like image 408
Eric the Red Avatar asked Sep 15 '25 15:09

Eric the Red


1 Answers

Foo.java:

package foopackage;

public class Foo {
    String getString() {
        return "foo";
    }
}

Bar.java:

package barpackage;

import foopackage.Foo;

public class Bar extends Foo {
    String getString() {
        return "bar";
    }
}

Should do it.

From the Eclipse Help docs:

A package default method is not visible in a different package, and thus cannot be overridden. When this option is enabled, the compiler will signal such scenario either as an error or a warning.

like image 94
Matt Ball Avatar answered Sep 17 '25 05:09

Matt Ball