how to replace anonymous with lambda in java

前端 未结 5 1044
别跟我提以往
别跟我提以往 2021-01-31 01:32

I\'ve got this code but IntelliJ tells me to replace anonymous with lambda but I don\'t know how. can anyone help me with this? Here is my code:

soundVolume.valu         


        
5条回答
  •  半阙折子戏
    2021-01-31 02:15

    It doesn't really help with the readability but here it is.

    Note that main's reference should be final or effectively final for this to work.

    soundVolume.valueProperty()
               .addListener(
               (ObservableValue ov, Number old_val, Number new_val) -> {
                   main.setSoundVolume(new_val.doubleValue());
                   main.getMediaPlayer().setVolume(main.getSoundVolume())
               });
    

提交回复
热议问题