我收到以下代码的错误:
private Supplier<ProfileData > expectedValidProfileData = () -> {
try {
ProfileData profileData = new ProfileData ();
return profileData ;
} catch (Exception ex) {
}
return null;
};
我不确定为什么,因为如果我直接从另一个不存在错误的文件复制代码
我注意到,如果删除 try-catch 语句,我不会收到错误
最佳答案
在 catch 部分添加 return 语句(根据需要异常(exception)),这就是它在没有 try-catch block 的情况下工作的原因
private Supplier<ProfileData > expectedValidProfileData = () -> {
try {
ProfileData profileData = new ProfileData ();
return profileData ;
} catch (Exception ex) {
//add return statement here
return null;
}
};
关于java - 为什么我收到供应商的 "Syntax error on token(s), misplaced construct(s)"错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57322380/