本月博客排行
年度博客排行
-
第1名
宏天软件 -
第2名
龙儿筝 -
第3名
青否云后端云 - wallimn
- gashero
- vipbooks
- wy_19921005
- benladeng5225
- fantaxy025025
- zysnba
- ssydxa219
- e_e
- javashop
- sam123456gz
- arpenker
- tanling8334
- kaizi1992
- xpenxpen
- xiangjie88
- wiseboyloves
- ganxueyun
- xyuma
- sichunli_030
- lemonhandsome
- wangchen.ily
- jh108020
- zxq_2017
- jbosscn
- Xeden
- zhanjia
- forestqqqq
- luxurioust
- lzyfn123
- johnsmith9th
- ajinn
- nychen2000
- wjianwei666
- daizj
- hanbaohong
- 喧嚣求静
- ranbuijj
- silverend
- kingwell.leng
- lchb139128
- kristy_yy
- lich0079
- jveqi
- java-007
- sunj
- yeluowuhen
最新文章列表
Java SE: Effective Java Notes "Concurrency"
Use the Advanced Concurrent Tools instead of the legacy wait() and notify().
Java Advanced Concurrent Tools:
1> Executor Framework: ExecutorService, Callable, Executors ...
2> Concur ...
Java SE: Effective Java Notes "Methods"
Effective Java 2nd Edition, Chapter 7, Item 42
Be careful when using var args. Do not abuse var args in our custmoized methods.
1) Painful Arrays.asList for Primitive Types
package edu.xmu.guava.co ...
Effective Java notes-Creating and Destroying Objects(1)
Item 1 Consider static factory method instead of constructors
Advantages:
One advantage of static factory methods is that, unlike constructors, they have names. (Mostly used in Java.utils.Colle ...
ActiveMQ 源码学习 2:从 CommandTypes 谈常量接口反模式
在上一篇文章里,我写了在阅读 ActiveMQ 的一小段源码时碰到的两种设计模式:抽象工厂和策略模式。实际上 ActiveMQ 源码量很大,只要认真分析,你会找到很多设计模式的应用场景。其中,有一个模式非常典型,并且它在整个 ActiveMQ 的源码架构中扮演者非常重要的角色,它就是 GoF 设计模式中的:命令模式(Command Pattern)。Command 是 ActiveMQ brok ...
Item 19: Use interfaces only to define types
1. Interfaces should be used only to define types. They should not be used to export constants.
2. The constant interface pattern is a poor use of interfaces. That a class uses some constants i ...
Item 18: Prefer interfaces to abstract classes
1. Existing classes can be easily retrofitted to implement a new interface.
2. Interfaces are ideal for defining mixins.
3. A mixin is a type that a class can implement in addition to its ...
第1条: 考虑用静态工厂方法替代构造器
1 考虑用静态工厂方法替代构造器
类可以提供一个公有的静态工厂方法,他只是一个返回类的实例的静态方法。
实例受控类
public static Boolean valueOf(boolean b)
{
return b ? Boolean.TRUE : Boolean.FALSE;
}
编写实例受控类有几个原因。实例受控使得类可以确保他是一个Singleton或者是不可实例化的。他 ...
Item 17: Design and document for inheritance or else prohibit it
1. The class must document precisely the effects of overriding any method. In other words, the class must document its self-use of overridable methods.
2. By convention, a method that invokes o ...
Item 16: Favor composition over inheritance
1. Inheriting from ordinary concrete classes across package boundaries is dangerous.
2. Unlike method invocation, inheritance violates encapsulation. The superclass’s implementation may change ...
Item 15: Minimize mutability
1. The Java platform libraries contain many immutable classes, including String, the boxed primitive classes, and BigInteger and BigDecimal.
2. Immutable classes are easier to design, implement ...
Item 14: In public classes, use accessor methods, not public fields
1. If a class is accessible outside its package, provide accessor methods to preserve the flexibility to change the class’s internal representation.
2. If a class is package-private or is a pri ...
Item 13: Minimize the accessibility of classes and members
1. A well-designed module hides all of its implementation details, cleanly separating its API from its implementation. Modules then communicate only through their APIs and are oblivious to each othe ...
Item 12: Consider implementing Comparable
1. compareTo is the sole method in the Comparable interface. By implementing Comparable, a class indicates that its instances have a natural ordering.
2. By implementing Comparable, you allow y ...
Item 11: Override clone judiciously
1. The Cloneable interface was intended as a mixin interface for objects to advertise that they permit cloning. However it lacks a clone method, and Object’s clone method is protected.
2. If a c ...
Item 10: Always override toString
1. The string returned by Object.toString consists of the class name followed by an “at” sign (@) and the unsigned hexadecimal representation of the hash code.
2. Providing a good toString imp ...
Item 8: Obey the general contract when overriding equals
1. A value class is simply a class that represents a value, such as Integer or Date. A programmer who compares references to value objects using the equals method expects to find out whether they are ...
Item 6: Eliminate obsolete object references
1. An obsolete reference is simply a reference that will never be dereferenced again.
2. Memory leaks in garbage-collected languages (more properly known as unintentional object retentions) are ...