当尝试使用 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) 我有一个Entity
带有字段id
和的实体列表createdDate
。我想对它们进行如下排序:
id
第一id
null,则最新的createdDate
优先我尝试了以下不成功的方法,因为它抛出一个NullPointerException
when 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时进行处理。我该如何处理这种情况?