-1

I am quite new to using java 8 & haven't really used annotations before. When I try to write a simple program for functional interface using eclipse oxygen, java 8 & specify annotation @FunctionalInterface, I see the red x (error) saying FunctionalInterface is not an annotation type.

Please help to resolve this. I understand that giving an annotation is not mandatory, also my program runs fine without it, but still I want to use it.

  • Javadoc says "However, the compiler will treat any interface meeting the definition of a functional interface as a functional interface regardless of whether or not a FunctionalInterface annotation is present on the interface declaration." So it definitely not mandatory. – talex Aug 06 '18 at 10:08
  • 3
    Have you perhaps defined a class called `FunctionalInterface`? Show us a [mcve] – greg-449 Aug 06 '18 at 10:10
  • 1
    Please share the code . – Dinesh Aug 06 '18 at 10:12
  • @talex The OP already said "I understand that giving an annotation is not mandatory" – khelwood Aug 06 '18 at 10:13
  • You really need to show your code. As it stands this question is not useful, and resolving it is impossible. – skomisa Aug 13 '18 at 01:02

6 Answers6

5

Hope you have not written your Interface as,

package com.practice;

@FunctionalInterface
public interface FunctionalInterface {
    void method1();
}

i.e the name of annotation and Interface is same. The same thing which is mentioned by @greg-449 in you comment section.

Janhavi Gadkari
  • 123
  • 2
  • 13
1

Please make sure if your Installed is pointing to jre 1.8 in eclipse to verify you can go to Window> Preferences >java> installed Jre if not then update it

0

You should have Java 8 installed and your Eclipse should use Java 8, however, with Java 8, I saw the same issue. It went away after I imported it manually:

import java.lang.FunctionalInterface;

Then I decided to just do a clean build and the problem went away even "without" the import statement.

blueSky
  • 649
  • 5
  • 13
  • 31
0

Clean your project at first and even if that doesn't fix your problem, try to close the project and open the project again.

Shabarinath Volam
  • 789
  • 5
  • 19
  • 48
0

Faced same issue as the name of interface was FunctionalInterface. Referring to earlier comments, updated the interface name and the annotation worked for me. No additional import is needed for @FunctionalInterface.

0

If you defined the class name as FunctionalInterface then no need to use @FunctionalInterface annotation. Rename the class Name and try it out.