小编Vin*_*yak的帖子

throw e和throw new Exception(e)有什么区别?

考虑:

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)

java exception try-catch throw

38
推荐指数
2
解决办法
5431
查看次数

如何在Postgres中的列上放置唯一约束?

这是我的数据库表

CREATE TABLE cart (
  id           UUID      NOT NULL PRIMARY KEY,
  shop_user_id UUID UNIQUE
);
Run Code Online (Sandbox Code Playgroud)

当我尝试删除UNIQUEshop_user_id我的约束42601 error

这是我用来删除唯一约束的查询

ALTER TABLE cart DROP UNIQUE shop_user_id;
Run Code Online (Sandbox Code Playgroud)

postgresql ddl constraints

4
推荐指数
1
解决办法
4940
查看次数

将函数作为参数传递给 Lambda java 8

我有以下方法:

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 lambda java-8 java-stream

3
推荐指数
1
解决办法
335
查看次数