[Google Guava] 1.1-使用和避免null】的更多相关文章

原文链接 译文链接 译者: 沈义扬    Doug Lea 说,“Null 真糟糕.”   当Sir C. A. R. Hoare 使用了null引用后说,”使用它导致了十亿美金的错误.” 轻率地使用null可能会导致很多令人惊愕的问题.通过学习Google底层代码库,我们发现95%的集合类不接受null值作为元素.我们认为, 相比默默地接受null,使用快速失败操作拒绝null值对开发者更有帮助. 此外,Null的含糊语义让人很不舒服.Null很少可以明确地表示某种语义,例如,Map.get(…
为什么使用optional 使用Optional<T>除了简化粗鲁的if(null == object).降低函数的复杂度.增加可读性之外,它是一种傻瓜式的防护,Optional<T>引导编码人员主动的思考引用为null的情况. 创建方法 Optional.of(T):获得一个Optional对象,其内部包含了一个非null的T数据类型实例,若T=null,则立刻报错.Optional.absent():获得一个Optional对象,其内部包含了空值Optional.fromNul…
Google Guava官方教程(中文版) 原文链接  译文链接 译者: 沈义扬,罗立树,何一昕,武祖  校对:方腾飞 引言 Guava工程包含了若干被Google的 Java项目广泛依赖 的核心库,例如:集合 [collections] .缓存 [caching] .原生类型支持 [primitives support] .并发库 [concurrency libraries] .通用注解 [common annotations] .字符串处理 [string processing] .I/O…
http://www.cnblogs.com/peida/tag/Guava/ Guava 是一个 Google 的基于java1.6的类库集合的扩展项目,包括 collections, caching, primitives support, concurrency libraries, common annotations, string processing, I/O, 等等. 这些高质量的 API 可以使你的JAVa代码更加优雅,更加简洁,让你工作更加轻松愉悦.下面我们就开启优雅Java…
It is an established good practice to validate method arguments at the beginning of the method body. For example you could check that the passed value is not negative before doing some calculation: 1 2 3 4 5 6 public int doSomeCalculation(int value)…
文章转载自:http://my.oschina.net/leejun2005/blog/172328 目录:[ - ] 1-使用 GOOGLE COLLECTIONS,GUAVA,STATIC IMPORTS 编写漂亮代码 1.Google Collections一览 2.操作lists和maps 3.静态导入和Eclipse模板 4.Guava走马观花 2-深入探索 GOOGLE GUAVA 库 1.The Guava CharMatcher 2.Joiner and Splitter 3.W…
一.简介 Google Guava包含了Google的Java项目许多依赖的库,如:集合 [collections] .缓存 [caching] .原生类型支持 [primitives support] .并发库 [concurrency libraries] .通用注解 [common annotations] .字符串处理 [string processing] .I/O 等等.本文只介绍其中的缓存部分. Guava Cache是一种本地缓存实现,支持多种缓存过期策略.性能好,简单易用.缓存…
翻译自Google Guava Cache This Post is a continuation of my series on Google Guava, this time covering Guava Cache. Guava Cache offers more flexibility and power than either a HashMap or ConcurrentHashMap, but is not as heavy as using EHCache or Memcache…
Guava地址:https://github.com/google/guava 第一次接触我是在16年春github上,当时在找单机查缓存方法,google guava当初取名是因为JAVA的类库不好用,所以谷歌工程师自己开发一套,想着google出品必属精品理念,我们一起来了解一下. guava在还没做分布式处理上,单机单整合上大行其道.所以guava在程序性能优化上下了不少的工夫,我们称其为单块架构的利器 我认为强大的有几点:1.集合处理   2.EventBus消息总线处理  3.guav…
环境 Apache Maven : 3.5.4 org.springframework.boot » spring-boot-starter-parent : 2.0.3.RELEASE io.springfox » springfox-swagger2 & io.springfox » springfox-swagger-ui : 2.9.2 org.codehaus.mojo » findbugs-maven-plugin : 3.0.5 运行项目错误 错误信息如下: org.springf…