You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Why are the results always true for this example in the engineering project? Wasn't the likes method redefined as (Function<String, Boolean>)(thing -> !thing.equals("relaxation"))?
private static void useMapStructuralInterface() {
out.println("\n\n### Use Maps with Structural Interfaces ###\n");
// Use a Map to directly back any interface
Dog dog = (Dog)new HashMap<>();
dog.setBreed("Foxhound");
((Map)dog).put("likes", (Function<String,Boolean>)(thing -> !thing.equals("relaxation")));
String breed = dog.getBreed();
out.println(breed);
out.println(dog.likes("ball"));
out.println(dog.likes("relaxation"));
}
@Structural
interface Dog {
String getBreed();
void setBreed(String breed);
default boolean likes(String thing) {
return true;
}
}
Run result :
The text was updated successfully, but these errors were encountered:
This is a bug dealing with default methods on interfaces. Dog#likes is a default method that returns true. It is called instead of the lambda. A fix for this issue will be in the next release this weekend. Thanks for reporting this!
Why are the results always true for this example in the engineering project? Wasn't the likes method redefined as
(Function<String, Boolean>)(thing -> !thing.equals("relaxation"))
?Run result :
The text was updated successfully, but these errors were encountered: