Principle readObject method is effectively another public constructor, and it demands all of the same care as any other constructor. Just as a constructor must check its arguments for validity (Item 38) and make defensive copies of parameters where a…
Java Native Interface(JNI) allows Java applications to call native methods, which are special methods written in native programming languages such as C or C++. Historical usages of native methods Access to platform-specific facilities such as registr…
Static utility methods are particularly good candidates for generification. The type parameter list, which declares the type parameter, goes between the method's modifiers and its return type. // Generic method public static <E> Set<E> union(S…
Hi guys, I am happy to tell you that I am moving to the open source world. And Java is the 1st language I have chosen for this migration. It's a nice chance to read some great books like "Effective Java 2nd Edition" and share the note for what I…
Chapter 11 Serialization Item 74: Implement Serializable judiciously 让一个类的实例可以被序列化不仅仅是在类的声明中加上"implements Serializable"那么简单. 当你的类implements Serializable并发布出去后,你对这个类的改动的灵活性将会大大降低,它的serialized form成为了它exported API的一部分,如果你不设计一个custom serialized for…
<Effective Java>目录摘抄. 我知道这看起来很糟糕.当下,自己缺少实际操作,只能暂时摘抄下目录.随着,实践的增多,慢慢填充更多的示例. Chapter 2 Creating and Destroying Objects Consider static factory methods instead of constructors Consider a builder when faced with many constructor parameters Enforce the s…
Tips <Effective Java, Third Edition>一书英文版已经出版,这本书的第二版想必很多人都读过,号称Java四大名著之一,不过第二版2009年出版,到现在已经将近8年的时间,但随着Java 6,7,8,甚至9的发布,Java语言发生了深刻的变化. 在这里第一时间翻译成中文版.供大家学习分享之用. 17. 最小化可变性 不可变类简单来说是它的实例不能被修改的类. 包含在每个实例中的所有信息在对象的生命周期中是固定的,因此不会观察到任何变化. Java平台类库包含许多不…
Java写了很多年,很惭愧,直到最近才读了这本经典之作<Effective Java>,按自己的理解总结下,有些可能还不够深刻 一.Creating and Destroying Objects Consider static factory methods instead of constructors (factory方法可以拥有名称,可以避免重复创建,比如单例模式) Consider a builder when faced with many constructor parameter…
Principle Do not accept the default serialized form without first considering whether it is appropriate.   The default serialized form is likely to be appropriate if an object's physical representation is identical to its logical content. @serial tag…
EFFECTIVE  JAVA  第十一章  系列化(将一个对象编码成一个字节流) 74.谨慎地实现Serializable接口 *实现Serializable接口付出的代价就是大大降低了“改变这个类的实现”的灵活性. *增加了出现Bug和安全漏洞的可能性.反系列化是一个“隐藏的构造器”,很难确保“由真正的构造器建立起来的关系” *增加了测试的负担 *transient关键字修饰的变量不会被初始化 *可以实现Externalizable接口来实现基于默认构造器的显示配置系列化  75.考虑使用自…