考虑:
try {
// Some code here
} catch (IOException e) {
throw e;
} catch (Exception e) {
throw e;
}
Run Code Online (Sandbox Code Playgroud)
throw e和之间有什么区别throw new Exception(e)?
try {
// Some code here
} catch (IOException e) {
throw new IOException(e);
} catch (Exception e) {
throw new Exception(e);
}
Run Code Online (Sandbox Code Playgroud) 这是我的数据库表
CREATE TABLE cart (
id UUID NOT NULL PRIMARY KEY,
shop_user_id UUID UNIQUE
);
Run Code Online (Sandbox Code Playgroud)
当我尝试删除UNIQUE对shop_user_id我的约束42601 error
这是我用来删除唯一约束的查询
ALTER TABLE cart DROP UNIQUE shop_user_id;
Run Code Online (Sandbox Code Playgroud) 我有以下方法:
public String getAllDangerousProductsName(Offer offer){
return offer.getOfferRows().stream()
.filter(row -> row.isDangerousGood())
.map(row -> row.getItemInformation().getOfferTexts().getName())
.collect(Collectors.joining(","));
}
Run Code Online (Sandbox Code Playgroud)
我想为 row.isBulkyGood() 重用这个方法。我目前正在做的是
public String getAllBulkyProductsName(Offer offer){
return offer.getOfferRows().stream()
.filter(row -> row.isBulkyGood())
.map(row -> row.getItemInformation().getOfferTexts().getName())
.collect(Collectors.joining(","));
}
Run Code Online (Sandbox Code Playgroud)
...这基本上是代码重复。有没有办法可以将函数作为方法参数传递来优化它,以便对两种过滤条件都有一种方法?
java ×2
constraints ×1
ddl ×1
exception ×1
java-8 ×1
java-stream ×1
lambda ×1
postgresql ×1
throw ×1
try-catch ×1