我有以下 lamda 表達式。我的 IDE(intellij 想法)告訴我它應該被替換,Comparator.comparingDouble但我找不到辦法。List<javafx.stage.Screen> screenList = screens;screenList.sort((screenA, screenB) -> Double.compare( screenA.getBounds().getMinX(), screenB.getBounds().getMinX()));有沒有辦法做到這一點screenList.sort(Comparator.comparingDouble(...));或者這是來自intellij的錯誤注釋?預先感謝您的幫助!
2 回答

陪伴而非守候
TA貢獻1757條經驗 獲得超8個贊
您只需要一個轉換Screen
為的函數double
:
screenList.sort(Comparator.comparingDouble(screen -> screen.getBounds().getMinX()));

慕勒3428872
TA貢獻1848條經驗 獲得超6個贊
在 Intellij IDEA 中,您只需在比較時調用快速修復(按 Alt+Enter),然后在建議替換為 Comparator.comparing double時單擊 Enter ,IDEA 將自動進行替換。
screenList.sort((screenA, screenB) -> Double.com<ALTENTER_HERE>pare( screenA.getBounds().getMinX(), screenB.getBounds().getMinX()));
代碼將替換為:
screenList.sort(Comparator.comparingDouble(screenA -> screenA.getBounds().getMinX()));
添加回答
舉報
0/150
提交
取消