最近,我习惯于用人类友好的类名“掩盖” Java集合。一些简单的例子:
// Facade class that makes code more readable and understandable.
public class WidgetCache extends Map<String, Widget> {
}
要么:
// If you saw a ArrayList<ArrayList<?>> being passed around in the code, would you
// run away screaming, or would you actually understand what it is and what
// it represents?
public class Changelist extends ArrayList<ArrayList<SomePOJO>> {
}
一位同事向我指出,这是一种不好的做法,并引入了延迟/潜伏期,并且是一种面向对象的反模式。我能理解它带来了很小的性能开销,但无法想象它是多么重要。所以我问:这是好事还是坏事,为什么?
implementation
ie HashMap
或TreeMap
and他有错别字。