我有以下三元表达式:
((!f.exists()) ? (f.createNewFile() ? printFile() : throw new Exception("Error in creating file")) : printFile());
出于一个或多个原因,我不知道IDE对我说这不是一个声明。为什么?
最佳答案
这无效,您需要返回一个值
printFile() : throw new Exception("Error in creating file")
试试这个
if(f.exists() || f.createNewFile()) {
printFile();
}else{
throw new Exception("Error in creating file");
}
关于java - 三元运算符不是一个语句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31582570/