@FunctionalInterface interface inter1 { public void show(); }
this program compiles and runs fine when I used 1.6 version to compile

- 21
- 1
- 2
2 Answers
A Functional Interface refers to an interface that has one non-default, and one non-static method. This concept was has always been existing.
This can be implemented either by a class that implements this interface or through a Lambda expression that was introduced from Java 8 onwards.

- 603
- 8
- 19
-
you are wrong mate functional interface is the interface which contains only one abstract method but it can have any number of default or static methods – Kuldeep Shrivastava Sep 21 '21 at 06:14
-
@KuldeepShrivastava One non-default and one non-static refers to one abstract method. It's another of saying it. – Sara Sep 21 '21 at 06:19
-
my question is that....if functional interface concept came in java version 8 so why this annotation "@FunctionalInterface " is working in java version 7 or past version it should throw error for "@FunctionalInterface" annotation – Kuldeep Shrivastava Sep 21 '21 at 13:08
Annotations that aren't available on the classpath at runtime are silently suppressed; this applies to any annotations generally.
Note that what you're doing is risky and is probably giving you warnings about mismatched target levels and JDKs; that's exactly because in other cases, using JDK features not available on the target will result in errors when trying to load the class at runtime. You got away with it only because it's an annotation, which is always optional.

- 75,269
- 21
- 115
- 152
-
bro as you said annotations are optional....try to change @FunctionalInterface spelling you will get error – Kuldeep Shrivastava Sep 21 '21 at 06:16
-
@KuldeepShrivastava You are confusing "available at compile time" with "available at runtime". – chrylis -cautiouslyoptimistic- Sep 21 '21 at 06:37
-
my question is that....if functional interface concept came in java version 8 so why this annotation "@FunctionalInterface " is working in java version 7 or past version it should throw error for "@FunctionalInterface" annotation....... are you getting my question – Kuldeep Shrivastava Sep 21 '21 at 13:10
-
It _isn't_ "working". You have JDK 8+ _on the compile-time classpath_ (which is giving you warnings), and classes available on the classpath can be used during compilation. – chrylis -cautiouslyoptimistic- Sep 21 '21 at 15:01
-
ohk mate I got it.....I'll test it by compiling it on jdk version 7 or past.......thanks – Kuldeep Shrivastava Sep 22 '21 at 06:46