jjzjj

ImmutableList

全部标签

java - 结合 guava 的 ImmutableList 和 varargs

我想创建一个构造函数,它将采用一个或多个整数并将其作为ImmutableList保存到字段中。根据Bloch的第42项“使用可变参数传递一个或多个参数的正确方法”,我创建了类似smtclassFoo{privatefinalImmutableListbar;publicFoo(Integerfirst,Integer...other){this.bar=ImmutableList.builder().add(first).addAll(Arrays.asList(other)).build();}}为什么构建器不会自动获取泛型?而且,因为它闻起来。我该如何重写它?更新泛型问题已解决。有

java - Guava:Iterables.filter VS Collections2.filter,有什么大的区别吗?

我想知道在Guava中Iterables.filter(Iterable,Predicate)之间是否有任何差异和Collections2.filter(Collection,Predicate)方法?它们似乎既维护迭代顺序,又提供实时View。Javadoc说调用Collections2.filter().size()将遍历所有元素。假设我有一个谓词来过滤项目列表,因此我想要View(或列表,无关紧要)中剩余的项目数。我应该用什么?使用Collections2.filter似乎更简单,因为Collection提供了size()方法。但是在后台,有没有区别:ImmutableList.

java - 如何创建一个空的 Guava ImmutableList?

我可以创建一个GuavaImmutableList与of方法,并将根据传递的对象获取正确的泛型类型:Foofoo=newFoo();ImmutableList.of(foo);但是,theofmethodwithnoparameters无法推断泛型类型并创建ImmutableList.如何创建一个空的ImmutableList满足List? 最佳答案 如果将创建的列表分配给变量,则无需执行任何操作:ImmutableListlist=ImmutableList.of();在其他无法推断类型的情况下,你必须写ImmutableList

java - 如何创建一个空的 Guava ImmutableList?

我可以创建一个GuavaImmutableList与of方法,并将根据传递的对象获取正确的泛型类型:Foofoo=newFoo();ImmutableList.of(foo);但是,theofmethodwithnoparameters无法推断泛型类型并创建ImmutableList.如何创建一个空的ImmutableList满足List? 最佳答案 如果将创建的列表分配给变量,则无需执行任何操作:ImmutableListlist=ImmutableList.of();在其他无法推断类型的情况下,你必须写ImmutableList

java - 没有这样的方法错误 : ImmutableList. copyOf()

我正在使用Guava-05-snapshot和Sun的JDK1.6执行此代码段的代码会爆炸:Listbadpasswords=Lists.newArrayList(Password.badWords);Collections.sort(badpasswords);ImmutableListtmp=ImmutableList.copyOf(badpasswords);特别是在ImmutableList.copyOf()调用上。此代码使用旧的Google-Collections代码已经工作了几个月。java.lang.NoSuchMethodError:com.google.common.

java - 没有这样的方法错误 : ImmutableList. copyOf()

我正在使用Guava-05-snapshot和Sun的JDK1.6执行此代码段的代码会爆炸:Listbadpasswords=Lists.newArrayList(Password.badWords);Collections.sort(badpasswords);ImmutableListtmp=ImmutableList.copyOf(badpasswords);特别是在ImmutableList.copyOf()调用上。此代码使用旧的Google-Collections代码已经工作了几个月。java.lang.NoSuchMethodError:com.google.common.

java - 为什么 Guava 的 ImmutableList 有这么多重载的 of() 方法?

我只是在看Guava的ImmutableList我注意到of()方法被重载了12次。在我看来,他们所需要的只是:staticImmutableListof();staticImmutableListof(Eelement);//notevennecessarystaticImmutableListof(E...elements);为什么会有这么多相似的变体? 最佳答案 可变参数和泛型不能很好地配合使用。Varargs方法可能会导致带有泛型参数的警告,并且重载会阻止该警告,除非您希望使用of()将超过11个项目添加到不可变列表中。来源

java - 为什么 Guava 的 ImmutableList 有这么多重载的 of() 方法?

我只是在看Guava的ImmutableList我注意到of()方法被重载了12次。在我看来,他们所需要的只是:staticImmutableListof();staticImmutableListof(Eelement);//notevennecessarystaticImmutableListof(E...elements);为什么会有这么多相似的变体? 最佳答案 可变参数和泛型不能很好地配合使用。Varargs方法可能会导致带有泛型参数的警告,并且重载会阻止该警告,除非您希望使用of()将超过11个项目添加到不可变列表中。来源

java - google 的 ImmutableList 和 Collections.unmodifiableList() 有什么区别?

来自ImmutableListjavadocs:UnlikeCollections.unmodifiableList(java.util.List),whichisaviewofaseparatecollectionthatcanstillchange,aninstanceofImmutableListcontainsitsownprivatedataandwillneverchange.ImmutableListisconvenientforpublicstaticfinallists("constantlists")andalsoletsyoueasilymakea"defensi

java - google 的 ImmutableList 和 Collections.unmodifiableList() 有什么区别?

来自ImmutableListjavadocs:UnlikeCollections.unmodifiableList(java.util.List),whichisaviewofaseparatecollectionthatcanstillchange,aninstanceofImmutableListcontainsitsownprivatedataandwillneverchange.ImmutableListisconvenientforpublicstaticfinallists("constantlists")andalsoletsyoueasilymakea"defensi