Search code examples
javainterfacejava-8default-method

default method in interface runs with command prompt but not in eclipse


interface G {
    default void print() {
        System.out.println("G");
    }
}
class M {
    public void print() {
        System.out.println("M");
    }
}
class GImpl extends M implements G {}
public class Wierd {
    public static void main(String[] args) {
        G g=new GImpl();
        g.print();
    }
}

i was trying to use default method in interface ,but when compile with eclipse i get error on line 2 -says delete default, but i compile and run with command prompt it runs fine,what could be the reason for this?


Solution

    • Your eclipse still not using Java8 version please check it might be less than 8.
    • Use System.out.println(System.getProperty("java.runtime.version")); to check.
    • You may also need to change build path of your project and compiler level in eclipse.

    AND More Important:

    Installing Java™ 8 support .