Google Guava API学习笔记(1):基础
Guava项目包括了多个Google的核心库,包括collections、caching、primitives 、concurrency libraries、common annotations、string processing、I/O等,他们被广泛用于Google项目的开发。
学习地址:http://code.google.com/p/guava-libraries/wiki/GuavaExplained?tm=6
[size=x-lOptional:通过它避免使用null,或说避免null的歧义性[/size]
避免用null,null是造成BUG的罪魁祸首,举个例子,通过Map#get(key),返回是null,既有可以是没有该键,也有可能是键对应的值是null,这种似是而非的情况容易造成程序Bug。
为解决这个问题,Guava引入了一个Optional:
来看一个Optional的使用:
Throwable getRootCause(Throwable)List<Throwable> getCausalChain(Throwable)String getStackTraceAsString(Throwable)