摘要:
概述ClassToInstanceMap提供了一种是用Class作为Key, 对应实例作为Value的途径.他定义了T getInstance(Class)和T putInstance(Class T)两个方法, 这两个方法消除了元素类型转换的过程并保证了元素在Map中是类型安全的.ClassToInstanceMap有一个独立的类型参数, 一般命名为B. 它对应着Map的元素的类型的最大上界.例如ClassToInstanceMap numberDefaults = MutableClassToInstanceMap.create();numberDefaults.putInstance(I 阅读全文
摘要:
Guava's fluent comparator class, Ordering, explained.explainedUpdatedJun 27, 2013bycpov...@google.comExample 例子assertTrue(byLengthOrdering.reverse().isOrdered(list));Overview 总览Orderingis Guava's "fluent"Comparatorclass, which can be used to build complex comparators and apply them 阅读全文
摘要:
Using Guava's precondition checking utilities, explained.explainedUpdatedApr 23, 2012bywasserman.louisPreconditionsGuava provides a number of precondition checking utilities. We strongly recommend importing these statically. (How to do this easily in Eclipse.)Guava提供了一系列precondition检查工具. 我们强烈推荐你 阅读全文
摘要:
概述Java中单例模式的实现有多重方法, 要实现单例模式主要的问题是线程安全问题以及对Lazy Load的考虑,主要有如下几种双重锁定懒加载单例预加载单例枚举单例双重锁定懒加载单例模式/** * 双重锁定懒加载单例实现 * * @author zhenwei.liu created on 2013 ... 阅读全文
摘要:
"Null sucks."-Doug Lea"Null 很恶心!""I call it my billion-dollar mistake."-Sir C. A. R. Hoare, on his invention of the null reference"我称它为我的十亿美元错误"Using and avoiding null 使用和避免nullCareless use ofnullcan cause a staggering variety of bugs. Studying the Google code 阅读全文
摘要:
概述Java中一共有四种Reference, 其中 SoftReference, WeakReference, PhantomReference内有一个Referent和ReferenceQueueReferent: 被引用对象RefernceQueue: 当引用的Referent被回收后该引用会被enqueue到这个ReferenceQueue中一个对象可以同时拥有多种引用, 可以通过Reference.get()方法获取ReferentStrongReference (强引用)强引用时Java中使用得最多的引用, 我们使用的普通引用就是Java强应用例如Object o = new Obj 阅读全文
摘要:
FinalizableReference/* * Copyright (C) 2007 The Guava Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * 阅读全文
摘要:
/* * Copyright (C) 2008 The Guava Authors Licensed under the Apache License, Version 2.0 (the "License"); you may not use * this file except in compliance with the License. You may obtain a copy of the License at * http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable la 阅读全文
摘要:
Reader是Java IO体系里字符处理读取流的基本类,代码如下/* * %W% %E% * * Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved. * ORACLE PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. */package java.io;/** * Abstract class for reading character streams. The only methods that a * subclass must . 阅读全文
摘要:
public class Test2 { public static void main(String[] args) { ArrayList list = newArrayList(); list.add("k"); list.add("b"); System.out.println(list.getClass()); // 这一句编译是不会通过的,因为编译器对pick()返回值的推断是Serializable或Comparable类型 // 亦即 String "a", list 这两个参数共同继承的... 阅读全文