首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 其他教程 > 开源软件 >

Google Guava API学习札记(1):基础

2012-09-24 
Google Guava API学习笔记(1):基础Guava项目包括了多个Google的核心库,包括collections、caching、primitive

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)



 

热点排行