java如何连接两个参数化类型的数组(在guava中)
我在寻找一种简单的方法来迭代两个数组。 由于预计阵列不会很大,我想我可以直接将它们连接起来
不幸的是,调用番石榴看起来很可怕:
Class<? extends MyInterface>[] a2 = ...
Class<? extends MyInterface>[] a1 = ...
ObjectArrays.concat(a1, a2,
(Class<Class<? extends MyInterface>>) MyInterface.class.getClass());
有没有可能让它更具可读性
# 1 楼答案
最后我写了一些自己的东西
有一种主要方法可以完成所有工作:
。。然后,对于每个参数组合(2..6),都有一个输入方法,如下所示:
等等
我认为一个人很少需要合并超过6个数组,如果需要的话,可以很容易地扩展给定的想法
# 2 楼答案
您可以将
Arrays.asList
和Iterables.concat
组合起来,而不是使用ObjectArrays
。这样,您就不需要提供类名如果使用静态导入,它的可读性将大大提高: