1
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?

saurabh kumar
  • 155
  • 5
  • 26

2 Answers2

2
  • 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 .

akash
  • 22,664
  • 11
  • 59
  • 87
1

It seems that you have installed Java 8 JDK but your eclipse still does not support Java 8. Eclipse Luna has support for Java 8. To change the compiler options Right Click your project>Properties>Java Compiler>Check on "Enable project specific settings">Then select Compiler Compliance level.enter image description here

Yasin
  • 1,906
  • 1
  • 21
  • 37