Google guava和Apache commons哪个好

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Google guava和Apache commons哪个好相关的知识,希望对你有一定的参考价值。

参考技术A

Guava 的 FAQ 部分有专门解答:


Why did Google build all this, when it could have tried to improve the Apache Commons Collections instead?
The Apache Commons Collections very clearly did not meet our needs. It does not use generics, which is a problem for us as we hate to get compilation warnings from our code. It has also been in a "holding pattern" for a long time. We could see that it would require a pretty major investment from us to fix it up until we were happy to use it, and in the meantime, our own library was already growing organically.
An important difference between the Apache library and ours is that our collections very faithfully adhere to the contracts specified by the JDK interfaces they implement. If you review the Apache documentation, you'll find countless examples of violations. They deserve credit for pointing these out so clearly, but still, deviating from standard collection behavior is risky! You must be careful what you do with such a collection; bugs are always just waiting to happen.
Our collections are fully generified and never violate their contracts (with isolated exceptions, where JDK implementations have set a strong precedent for acceptable violations). This means you can pass one of our collections to any method that expects a Collection and feel pretty confident that things will work exactly as they should.



简单地说:
Apache Commons Collections 3.x 不支持泛型,Guava 支持
Guava 实现了 JDK 的标准接口,而 Apache Commons Collections 3.x 有很多违反标准的地方

Apache Commons Collections 4.x 的发行注记如下:


Major changes since 3.2.1
Use of generics and other language features introduced in Java 5 (varargs, Iterable)
Removed deprecated classes / methods and features which are now supported by the JDK
Replaced Buffer interface with java.util.Queue
Added concept of split maps with respective interfaces Put / Get (see also package splitmap)
Added new Trie interface together with an implementation of a Patricia Trie



从 4.x 开始,Apache Commons Collections 开始使用 JDK 5 的特性(包括泛型),此外也去除、添加了很多内容


各有千秋, 我主要使用 Apache Commons ,辅助使用  Google guava

以上是关于Google guava和Apache commons哪个好的主要内容,如果未能解决你的问题,请参考以下文章

tried to access methos com.google.common.base.Stopwatch.<init>()V from class org.apache.hadoop...(代码

Google guava工具类的介绍和使用

Google guava工具类的介绍和使用

Atitit apache 和guava的反射工具

Guava 教程1-使用 Google Collections,Guava,static imports 编写漂亮代码

在模块 guava-20.0.jar (com.google.guava:guava:20.0) 中发现重复的类 com.google.common.util.concurrent.Listenabl