为什么OptionalInt类中没有mapToInt()? [英] Why is there no mapToInt() in the OptionalInt class?

查看:175
本文介绍了为什么OptionalInt类中没有mapToInt()?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

IntStream 类有 map() mapToObj() mapToLong() mapToDouble()方法,但<$ $中似乎缺少这些方法c $ c> OptionalInt class。

The IntStream class has map(), mapToObj(), mapToLong() and mapToDouble() methods, but those methods seem to be missing from the OptionalInt class.

这些方法是否有充分理由丢失?

Is there a good reason for those methods to be missing?

推荐答案

相当迟钝你可以做

OptionalInt oi = OptionalInt.of(1);
oi.ifPresent(i -> IntStream.of(i).map(j -> j + 1).forEach(System.out::println));

但不清楚为什么 OptionalInt 不能没有与 IntStream 相同的方法,尽管我注意到可选有一个 Stream <的子集/ code>

However it is not clear why OptionalInt doesn't have the same methods as IntStream although I note Optional has a subset of Stream

这篇关于为什么OptionalInt类中没有mapToInt()?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆