-2

I am trying to make a simple Interpreter for Java. Out teacher gave us a code to modify to reach our goal, but Eclipse doesn't like the keyword 'default'

enter image description here

The error is "Syntax error on token "default", delete this token"

I think it depends from my JDK version of java, this is what i am using

enter image description here

What should i modify?

Edit: i have Java 8 installed, but Eclipse doesn't allow me to change my compilance level over 1.7

enter image description here

Stefano Berti
  • 141
  • 1
  • 11
  • upgrade to java-8 – Blip Jun 25 '17 at 11:19
  • *"i have Java 8 installed, but Eclipse doesn't allow me to change my compilance level over 1.7"* - Because that not Java 8. A directory called "Java 8" doesn't mean that Java 8 is actually inside. Check what `[path to java]/jre/bin/java -version` is telling you. – Tom Jun 25 '17 at 11:38
  • stefano@berti-casa:/usr/lib/jvm/java-8-oracle/bin$ ./java -version java version "1.8.0_131" Java(TM) SE Runtime Environment (build 1.8.0_131-b11) Java HotSpot(TM) Server VM (build 25.131-b11, mixed mode) I think this is Java 8, but i am not sure i am using this in Eclipse, how can i check it? – Stefano Berti Jun 25 '17 at 11:51
  • The path is already visible in the second picture. – Tom Jun 25 '17 at 11:53
  • So i am using the right version of JRE, the problem could be the JDK? – Stefano Berti Jun 25 '17 at 11:58
  • What release of Eclipse is this? You need Luna (4.4), Mars (4.5) or Neon (4.6) to support Java 8. – greg-449 Jun 25 '17 at 15:11

3 Answers3

0

Interface Default Methods introdced only in Java 8

Download jdk 8 and use it in Eclipse

Download

Ori Marko
  • 56,308
  • 23
  • 131
  • 233
0

This is because you are using JRE JavaSE-1.7:

JRE

This JRE isis prior to Java 8, where default keyword has been introduced for defining default implementations of interface methods.

Switch JRE version to 1.8 to fix this problem.

Sergey Kalinichenko
  • 714,442
  • 84
  • 1,110
  • 1,523
0

Basically you just can not use/define an default method, because those are available since java 8 (and your project is using java7)... so you need to move the project to java8.

Oracle can help you, check this here

http://www.oracle.com/technetwork/java/javase/8-whats-new-2157071.html

is the What's New in JDK 8 part, 3rd element in the list....

  • Default methods enable new functionality to be added to the interfaces of libraries and ensure binary compatibility with code written for older versions of those interfaces.
ΦXocę 웃 Пepeúpa ツ
  • 47,427
  • 17
  • 69
  • 97