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

Pattern matching for instanceof #2388

Open
blazek opened this issue Sep 10, 2024 · 1 comment
Open

Pattern matching for instanceof #2388

blazek opened this issue Sep 10, 2024 · 1 comment
Assignees

Comments

@blazek
Copy link

blazek commented Sep 10, 2024

How can I get "pattern matching for instanceof" working?

The issue #2345 states that "You can use post-Java11 features that are implemented by javac, like switch expressions, text blocks, and pattern matching for instanceof."

I have j2objc master compiled with jdk 17, running with Java 17, it silently converts pattern matching for instanceof but the variable to which it should be casted, is not declared in objc output. For example:

if ( o instanceof List l ) {
    l.clear();
}

is converted to (regardless -XDallVersions -source 17 options):

if ([o isKindOfClass:[JavaUtilArrayList class]]) {
    [l clear];
}
@tomball
Copy link
Collaborator

tomball commented Sep 10, 2024

How can I get "pattern matching for instanceof" working?

Can't do that now, as new Java language features in Java 17 aren't implemented yet (I'm currently working on Java Records). The j2objc translator gets those new language features that are "syntactic sugar" automatically, since it uses javac as its front-end. Those features that require code generation changes require j2objc to be updated.

@tomball tomball self-assigned this Sep 10, 2024
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