片断 1:
public A appendTo(A appendable, Iterator parts) throws IOException {
checkNotNull(appendable);
if (parts.hasNext()) {
appendable.append(toString(parts.next()));
while (parts.hasNext()) {
appendable.append(separator);
appendable.append(toString(parts.next()));
}
}
return appendable;
}
片断 2:
public final A appendTo(A appendable, @Nullable Object first, @Nullable Object second, Object... rest) throws IOException {
return appendTo(appendable, iterable(first, second, rest));
}
private static Iterable iterable(final Object first, final Object second, final Object[] rest) {
checkNotNull(rest);
return new AbstractList() {
@Override public int size() {
return rest.length + 2;
}
@Override public Object get(int index) {
switch (index) {
case 0:
return first;
case 1:
return second;
default:
return rest[index - 2];
}
}
};
}
欢迎来到这里!
我们正在构建一个小众社区,大家在这里相互信任,以平等 • 自由 • 奔放的价值观进行分享交流。最终,希望大家能够找到与自己志同道合的伙伴,共同成长。
注册 关于