0

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

2 Answers2

1

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.

Sara
  • 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
0

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.

chrylis -cautiouslyoptimistic-
  • 75,269
  • 21
  • 115
  • 152