为什么我收到供应商"Syntax error on token(s), misplaced construct(s)"错误?



我在以下代码中获取错误:

private Supplier<ProfileData > expectedValidProfileData = () -> {
    try {
        ProfileData profileData = new ProfileData ();
        return profileData ;
    } catch (Exception ex) {
    }
    return null;
};

我不确定为什么,因为如果我直接从不存在错误的另一个文件复制代码

我注意到,如果我删除了try-catch语句

,我不会遇到错误

在捕获部分中添加返回语句(根据需要例外(,这就是为什么它在没有try-catch块

的情况下工作的原因
private Supplier<ProfileData > expectedValidProfileData = () -> {
    try {
        ProfileData profileData = new ProfileData ();
        return profileData ;
    } catch (Exception ex) {
         //add return statement here
         return null;
    }
};

最新更新