When I implement interfaces as a Lambda expression in my main method, it doesn't count as if it was implemented.
I know I can implement it outside of the main method, but I don't see why I should use Lambda expressions if I have to implement it outside of the main anyway.
public class Driver implements Interface1, Interface2, Interface3 {
public static void main(String[] args) {
//Implementing Interface1
double x;
Interface1 obj = () -> 5.5;
x = obj.foo();
System.out.println(x);
//Implementing Interface2
String str;
Interface2 obj2 = (a) -> String.format("The number is %d", a);
str = obj2.foo(356);
System.out.println(str);
//Implementing Interface3
boolean tF;
Interface3 obj3 = (i, s) -> i == Integer.parseInt(s);
tF = obj3.foo(30, "30");
System.out.print(tF);
}
Here, I get an error message at line 1 telling me that the Interfaces are not implemented. It still compiles and works, I just don't understand why I get this message. The output is currently:
5.5
The number is 356
true