Java的流8带参数的地图

该卡博:

我有这对夫妻的功能,我想知道是否可以将参数传递deviceEvent.hasAlarm().map(this::sendSMS)

private void processAlarm (DeviceEvent deviceEvent)  {

        notificationsWithGuardians.stream()
                    .filter (notification -> notification.getLevels().contains(deviceEvent.getDeviceMessage().getLevel()))
                    .map(this::sendSMS)
                    .map(this::sendEmail);

    }

    private DeviceAlarmNotification sendSMS (DeviceAlarmNotification notification, DeviceEvent deviceEvent)  {

        if (deviceEvent.hasAlarm()) {       

        }

        return notification;

    }
安迪·特纳:

使用lambda代替方法参考。

// ...
.map(n -> sendSMS(n, deviceEvent))
// ...

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章