Faced the following problem: Java 8 does not compile the code with the default method in the interface. At the same time I work exactly on the 8th version: C: \ Program Files \ Java \ jdk1.8.0_51 \ bin \ javaw.exe

interface Colorable{ void colored (); // абстрактный метод default void white(){ // метод по умолчанию. Syntax error on token default System.out.println("белый по умолчанию"); } } class Shape implements Colorable { public void colored (){ System.out.println("окрашен цветом"); } } public class Main { public static void main(String[] args) { Shape b = new Shape(); b.colored(); } } 

I use Eclipse Build id: 20140224-0627

Syntax error on token "default", delete this token

The type Shape must implement the inherited abstract method

Console Message:

 Colorable.white() Exception in thread "main" java.lang. Error: Unresolved compilation problem: at interfDefaultsMetodyPack.Main.main(Main.java:14) 
  • Read here - Vladimir Glinskikh
  • Thank! But the answer to my question is not there. - junior
  • using javac not played. In what environment do you work with code? - zRrr Nov.
  • An error message is possible? - Nofate
  • I use Eclipse Build id: 20140224-0627 1) Syntax error on token "default", delete this token 2) The type Shape must implement the inherited abstract method Error: Unresolved compilation problem: at interfDefaultsMetodyPack.Main.main (Main.java:14) - junior

1 answer 1

In general, a screen would be good, but I suspect that you do not have 1.8 in the build settings.

The fact that you specified Java 8 in the settings does not mean that the development environment will be build from 1.8

If it is Eclipse, then he likes to choose Java 1.5 by default.

It should be like this:

enter image description here

I understand you have Eclipse Kepler? Upgrade to Eclipse Luna at least.

UPD: you can still try to update Kepler: Help -> Install new sofware. And then enter http://download.eclipse.org/eclipse/updates/4.3-P-builds/

  • project build settings: Project Properties -> Java Compiler - Suvitruf
  • 1.7 ipic.su/jGQQ.jpg - junior
  • @junior select 1.8 - Suvitruf
  • and I have 1.7 and put 1.8 is not possible for some reason, how can this be. Maybe that Eclipse does not support 1.8? - junior