摘要:
The Enum specification has this to say about ordinal: “Most programmers will have no use for this method. It is designed for use by general-purpose enum based data structures such as EnumSet and EnumMap.” Unless you are writing such a data structure, you are best off avoiding the ordinal method entirely. 阅读全文
阅读排行榜
Effective Java 77 For instance control, prefer enum types to readResolve
2014-05-11 20:40 by 小郝(Kaibo Hao), 469 阅读, 收藏,
摘要:
You should use enum types to enforce instance control invariants wherever possible. If this is not possible and you need a class to be both serializable and instance-controlled, you must provide a readResolve method and ensure that all of the class's instance fields are either primitive or transient. 阅读全文
Effective Java 75 Consider using a custom serialized form
2014-05-09 07:39 by 小郝(Kaibo Hao), 469 阅读, 收藏,
摘要:
when you have decided that a class should be serializable (Item 74), think hard about what the serialized form should be. Use the default serialized form only if it is a reasonable description of the logical state of the object; otherwise design a custom serialized form that aptly describes the object. You should allocate as much time to designing the serialized form of a class as you allocate to designing it 阅读全文
Effective C# 学习笔记(六)理解各种“等运算”操作
2011-07-03 22:50 by 小郝(Kaibo Hao), 467 阅读, 收藏,
摘要:
关于C#中的“等运算”你了解多少,何时该重载你的类的Equals方法? 阅读全文
JavaScript Patterns 3.4 Array Literal
2014-05-30 23:03 by 小郝(Kaibo Hao), 466 阅读, 收藏,
摘要:
To avoid potential errors when creating dynamic arrays at runtime, it's much safer to stick with the array literal notation. 阅读全文
Effective Java 26 Favor generic types
2014-03-20 06:50 by 小郝(Kaibo Hao), 466 阅读, 收藏,
摘要:
Generic types are safer and easier to use than types that require casts in client code. When you design new types, make sure that they can be used without such casts. This will often mean making the types generic. Generify your existing types as time permits. This will make life easier for new users of these types without breaking existing clients (Item 23). 阅读全文
Effective C# 学习笔记(四十四)合理地在C#中使用Dynamic特性
2011-08-05 20:13 by 小郝(Kaibo Hao), 466 阅读, 收藏,
摘要:
尽管C# 4.0中添加了 Dynamic特性,但是本质上说C#还是一个静态语言。而过多的使用动态特性会是你的程序难于维护,易于出错,所以我们要讲一个“度”字。
原则是:在必须使用Dynamic的时候使用之,但将使用Dynamic的逻辑的地方用静态类型的方式封装起来供外界调用。(如使用范型转换Dynamic类型) 阅读全文
Effective Java 25 Prefer lists to arrays
2014-03-19 08:57 by 小郝(Kaibo Hao), 465 阅读, 收藏,
摘要:
Arrays are covariant and reified; generics are invariant and erased. As a consequence, arrays provide runtime type safety but not compile-time type safety and vice versa for generics. If you find yourself mixing them and getting compile-time errors or warnings, your first impulse should be to replace the arrays with lists. 阅读全文
Effective Java 19 Use interfaces only to define types
2014-03-14 08:06 by 小郝(Kaibo Hao), 461 阅读, 收藏,
摘要:
The constant interface pattern is a poor use of interfaces.
That a class uses some constants internally is an implementation detail. Implementing a constant interface causes this implementation detail to leak into the class's exported API.
It represents a commitment: if in a future release the class is modified so that it no longer needs to use the constants, it still must implement the interface to ensure binary compatibility. 阅读全文
JavaScript Patterns 5.1 Namespace Pattern
2014-06-22 23:16 by 小郝(Kaibo Hao), 457 阅读, 收藏,
摘要:
This post introduces how to maintain the namespace in JavaScript gracefully. 阅读全文
浙公网安备 33010602011771号