Java final domain

Source: Internet
Author: User

1  Public Final classThreestooges {2     3     4     /*5 * Stooges is a reference to the Set<string> type, and final qualifies the reference member property stooges to be assigned an initial value and cannot be changed to refer to other similar objects6 * Final only limits the declaration of the reference Stooges cannot be changed, stooges the referenced object can not be changed, by the referenced object itself class definition to determine7      */8     Private FinalSet<string> stooges =NewHashset<string>();9     Ten      Publicthreestooges () { OneStooges.add ("Moe")); AStooges.add ("Larry"); -Stooges.add ("Curly"); -          the         //stooges = new Hashset<string> ();//The final field threestooges.stooges cannot be assigned -     } -      -     /** + * Add an element to the referenced hashset - * Final domain stooges still refers to the HashSet object when the initial value is assigned, and Stooges.add (name); just add an element to the referenced hashset +      * @paramname A      */ at      Public voidAdd (String name) { - Stooges.add (name); -     } -      -      -      Public BooleanIsstooge (String name) { in         returnstooges.contains (name); -     } to      +      -      Public voidprint () { theIterator<string> Iterator =stooges.iterator (); *          while(Iterator.hasnext ()) { $System.out.println (Iterator.next () + ",");Panax Notoginseng         } -     } the      +      A      Public Static voidMain (string[] args) { the          +          -Threestooges ts =Newthreestooges (); $Ts.add ("ASN"); $ Ts.print ();  -     } -}

Output:

Moe,
Asn
Curly,
Larry,

Java final domain

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.