Monkeying around with Java 8 lambdas. Why does this give me an error when I add another method to my interface:
interface Something {
public String doit(Integer i);
public int getID(String name);.....
Something s = (Integer i) -> {
return i.toString();
};
System.out.println(s.doit(4));
Something y = (Integer i) -> {
return "do nothing";
};
System.out.println(y.doit(4));
Works fine without the second method: "public int getID(String name)
Java lambdas and method references may only be assigned to a functional interface. From Java SE 8 API, description of
java.util.function
package:JLS 9.8 also discusses this:
An interesting effect occurs with generics: