Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Why are the results always true for this example in the engineering project #4

Closed
css521 opened this issue Apr 6, 2023 · 2 comments

Comments

@css521
Copy link

css521 commented Apr 6, 2023

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 :
image

@rsmckinney
Copy link
Member

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!

@rsmckinney
Copy link
Member

rsmckinney commented Apr 8, 2023

Fix available with release 2023.1.5. See manifold-systems/manifold#436.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants