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

feat: support instance of pattern matching #476

Merged

Conversation

clementdessoude
Copy link
Contributor

@clementdessoude clementdessoude commented Jun 4, 2021

What changed with this PR:

Support instance of pattern matching: https://docs.oracle.com/javase/specs/jls/se16/html/jls-15.html#jls-InstanceofExpression

Example

// Input
class T {
    static String formatter(Object o) {
        String formatted = "unknown";
        if (o instanceof Integer i || p instanceof Point || q instanceof Circle c || r instanceof Square) {
            formatted = String.format("int %d", i);
        } else if (o instanceof Long l) {
            formatted = String.format("long %d", l);
        } else if (o instanceof Double d) {
            formatted = String.format("double %f", d);
        } else if (o instanceof String s) {
            formatted = String.format("String %s", s);
        }
        return formatted;
    }
}

// Output
class T {

  static String formatter(Object o) {
    String formatted = "unknown";
    if (
      o instanceof Integer i ||
      p instanceof Point ||
      q instanceof Circle c ||
      r instanceof Square
    ) {
      formatted = String.format("int %d", i);
    } else if (o instanceof Long l) {
      formatted = String.format("long %d", l);
    } else if (o instanceof Double d) {
      formatted = String.format("double %f", d);
    } else if (o instanceof String s) {
      formatted = String.format("String %s", s);
    }
    return formatted;
  }
}

Relative issues or prs:

Closes #434

@clementdessoude clementdessoude merged commit 5cc2fce into jhipster:main Jun 10, 2021
@clementdessoude clementdessoude deleted the feat/pattern-matching-support branch June 18, 2021 19:14
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

Successfully merging this pull request may close these issues.

Support preview feature: Pattern Matching for instanceof
2 participants