Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/353.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 重构lamda表达式以使用Comparator.comparingDouble_Java_Intellij Idea_Lambda - Fatal编程技术网

Java 重构lamda表达式以使用Comparator.comparingDouble

Java 重构lamda表达式以使用Comparator.comparingDouble,java,intellij-idea,lambda,Java,Intellij Idea,Lambda,我有一个如下的lamda表达式。我的IDE(IntellijIDEA)告诉我应该用比较器来代替它。comparingDouble但是我找不到一种方法来实现它 List<javafx.stage.Screen> screenList = screens; screenList.sort((screenA, screenB) -> Double.compare( screenA.getBounds().getMinX(), screenB.getBo

我有一个如下的lamda表达式。我的IDE(IntellijIDEA)告诉我应该用
比较器来代替它。comparingDouble
但是我找不到一种方法来实现它

List<javafx.stage.Screen> screenList = screens;

screenList.sort((screenA, screenB) -> Double.compare(
               screenA.getBounds().getMinX(), screenB.getBounds().getMinX()));


或者这是intellij的错误注释?提前感谢您的帮助

您只需要一个将
屏幕
转换为
双精度
的函数:

screenList.sort(Comparator.comparingDouble(screen -> screen.getBounds().getMinX()));

您只需要一个将
Screen
转换为
double
的函数:

screenList.sort(Comparator.comparingDouble(screen -> screen.getBounds().getMinX()));

在Intellij IDEA中,您只需在比较处调用quick fix(按Alt+Enter),然后在建议处单击Enter替换为Comparator。比较两次,IDEA将自动进行替换

screenList.sort((screenA, screenB) -> Double.com<ALTENTER_HERE>pare(
            screenA.getBounds().getMinX(), screenB.getBounds().getMinX()));

在Intellij IDEA中,您只需在比较处调用quick fix(按Alt+Enter),然后在建议处单击Enter替换为Comparator。比较两次,IDEA将自动进行替换

screenList.sort((screenA, screenB) -> Double.com<ALTENTER_HERE>pare(
            screenA.getBounds().getMinX(), screenB.getBounds().getMinX()));

非常感谢!:)非常感谢!:)