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

Underriding toString will select invalid static method in preference to valid default method #1508

Open
stevenschlansker opened this issue Mar 22, 2024 · 0 comments

Comments

@stevenschlansker
Copy link
Contributor

stevenschlansker commented Mar 22, 2024

Hi,
I am trying out the "underride" feature to add a custom toString.

I ended up with code like:

@Value.Immutable
@Value.Style(underrideToString = "join")
interface JoinThings {
    List<String> things();

    default String join() {
        return String.join(",", things());
    }

    static String join(String... things) {
        return of(things).join();
    }

    ...
}

The static join method, despite having an incorrect type signature for the "underride" feature seems to shadow the default. The generated code has a syntax error:

  /**
   * Prints the immutable value {@code JoinThings} delegating to a customized method.
   * @return A string representation of the value
   */
  @Override
  public String toString() {
    return JoinThings.join(this);
  }

The method join(String...) in the type JoinThings is not applicable for the arguments (ImmutableJoinThings)

By removing or renaming the static method, the default method is then correctly chosen for the underride implementation.
Should the code generator ignore incorrectly typed overloads of underrides, if there is a better typed alternate option?

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

1 participant