Generic InternPool in Java?

后端 未结 6 1157
天涯浪人
天涯浪人 2021-01-12 01:04

How would I write a generic InternPool in Java? Does it need a Internable interface?

String in Java has interning cap

6条回答
  •  清酒与你
    2021-01-12 01:44

    This more sounds like that you're looking for flyweight pattern.

    Flyweight is a software design pattern. A flyweight is an object that minimizes memory use by sharing as much data as possible with other similar objects

    Click the link, it contains a Java example.

提交回复
热议问题