通用InternPool T在Java中?
问题描述:
如何用Java编写通用的InternPool<T>
?是否需要Internable
接口?
How would I write a generic InternPool<T>
in Java? Does it need a Internable
interface?
String
具有实习功能;我想实习像BigDecimal
和Account
这样的类.
String
in Java has interning capabilities; I want to intern classes like BigDecimal
and Account
.
答
例如,请查看Internable
接口,它仅依赖于equals
和hashCode
.
For an example take a look at Interner
from Guava. It does not require an Internable
interface, it just relies on equals
and hashCode
.