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

java17模式匹配下if语句体编译报错 #13

Open
qw623577789 opened this issue Jun 9, 2022 · 0 comments
Open

java17模式匹配下if语句体编译报错 #13

qw623577789 opened this issue Jun 9, 2022 · 0 comments

Comments

@qw623577789
Copy link

    @Async
    private JPromise<Void> simpleAwait() {
        Object obj = null;
        
        // 这种写法没问题
        if (obj instanceof String) {
            String stringObj = (String) obj;
            JAsync.just(null).await();
            System.out.println(stringObj);
        }

        // 这种写法编译报错
        if (obj instanceof String stringObj) {
            JAsync.just(null).await();
            System.out.println(stringObj);
        }
        return JAsync.just(null);
    }

    public static void main(String[] args) {
        App app = new App();
        System.out.println(app.simpleAwait().block());
    }


System.out.println(stringObj);
^
符号: 变量 stringObj
位置: 类 App

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