小编Ser*_*ema的帖子

如何解决Python诗歌依赖错误

当尝试使用 Poetry 安装 Python 依赖项时,出现以下错误:

$ poetry install                                                                                                    
The currently activated Python version 2.7.15 is not supported by the project (>=3.6).
Trying to find and use a compatible version.
Using python3 (3.7.4)
Skipping virtualenv creation, as specified in config file.
Updating dependencies
Resolving dependencies... (1.7s)

[SolverProblemError]
The current project's Python requirement (>=3.6) is not compatible with some of the required packages Python requirement:
  - pre-commit requires Python >=3.6.1

Because no versions of pre-commit match >2.2.0,<3.0.0
 and pre-commit (2.2.0) requires Python …
Run Code Online (Sandbox Code Playgroud)

python-3.x python-poetry pre-commit.com

8
推荐指数
1
解决办法
2万
查看次数

具有空字段的Java比较器

我有一个Entity带有字段id和的实体列表createdDate。我想对它们进行如下排序:

  • 更高的id第一
  • 如果为idnull,则最新的createdDate优先

我尝试了以下不成功的方法,因为它抛出一个NullPointerExceptionwhen id为null

Comparator comp = Comparator
                .nullsFirst(Comparator.comparing(e -> ((Entity) e).getId()))
                .thenComparing(e -> ((Entity e).getCreatedDate())
                .reversed();
entities.stream().sorted(comp).findFirst();
Run Code Online (Sandbox Code Playgroud)

对于我所看到的,Comparator.nullsFirst当实体为null时进行处理,而不是在要比较的字段为null时进行处理。我该如何处理这种情况?

java sorting java-8 java-stream

6
推荐指数
1
解决办法
216
查看次数