Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use multiple instance mode multiton

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article mainly explains "how to use multi-case mode multiton". The explanation content in this article is simple and clear, easy to learn and understand. Please follow the idea of Xiaobian to study and learn "how to use multi-case mode multiton" together.

In the singleton pattern, we can only get one instance of each class. And in many cases, we can get a limited number of instances of this class, which are creative design patterns,

public enum FruitType { APPLE, BANANA;}public class Fruit { private String name; private Fruit(String name) { this.name = name; } private static ConcurrentHashMap fruits; static { fruits.put(APPLE,new Fruit("pinguo")); fruits.put(BANANA,new Fruit("xiangjiao")); } public static Fruit getFruit(FruitType fruitType){ return fruits.get(fruitType); }}public static void main(String[] args) { Fruit apple = Fruit.getFruit(FruitType.APPLE); Fruit banana = Fruit.getFruit(FruitType.BANANA); } Thank you for reading, the above is the content of "how to use multi-case mode multiton", after learning this article, I believe that everyone has a deeper understanding of how to use multi-case mode multiton, and the specific use needs to be verified by practice. Here is, Xiaobian will push more articles related to knowledge points for everyone, welcome to pay attention!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report