如何从单个元素构造 FluentIterable?

How to construct FluentIterable from a single element?

这是番石榴 FluentIterable.of(E[] e)

的 API

我希望它像 FluentIterable.of(E... e) 那样,这样我就可以从单个元素构建它。

我是不是漏掉了什么或者有什么特殊原因可以避免这种情况?

现在,我的代码是

FluentIterable.from(Lists.newArrayList(singleElement));//UGLY

谢谢。

看起来就像它即将到来(参见Improve FluentIterable.of to take variable # of arguments. by scr · Pull Request #2136 · google/guava; see also Factory method to create a FluentIterable from an array · Issue #1070 · google/guava)。

也许在 Guava 20 中?

是的,这将出现在 Guava 20.0 中: https://github.com/google/guava/commit/b01e8df8a7ffdcd3d52c960aadb044fefaafc8ba#diff-5801d092caa7673b9c43544c7ad01d4d