generics - java: how do I stop people from clearing my arraylist When I use a getter method? -


मैंने कक्षा A में मेरी arraylist घोषित किया है:

  निजी ArrayList & lt; स्ट्रिंग & gt; उपयोगकर्ता = नया अर्रेलिस्ट & lt; स्ट्रिंग & gt; ();   

मैंने अपनी कक्षा को एक ही वर्ग (कक्षा ए) में बनाया है:

  सार्वजनिक ऐरे लिस्ट & lt; स्ट्रिंग & gt; getUser () {वापसी उपयोगकर्ता; }   

फिर मेरे द्वितीय श्रेणी (कक्षा बी) में मैं निम्नलिखित करने में सक्षम हूं:

  एक यूडी = नया ए (); UD.getUser () स्पष्ट ()।; UD.getErrmsg () स्पष्ट ()।;   

मैं अपनी पहली कक्षा (कक्षा ए) में सरली सूची को साफ करने से कैसे मेरी दूसरी कक्षा को रोकूं?

इस का एक तरीका संग्रह वर्ग में आप उपयोग कर सकते हैं: return Collections.unmodifiableList (उपयोगकर्ता); जिन तरीकों के लिए आपको आवश्यकता हो सकती है, इनमें से एक के नक्शे और इसके आगे भी शामिल हैं। बस पर एक लूप लें।

Comments

Popular posts from this blog

Verilog Error: output or inout port "Q" must be connected to a structural net expression -

Installing croogo for cakephp -

c# - ASP.NET MVC - Attaching an entity of type 'MODELNAME' failed because another entity of the same type already has the same primary key value -