The delayed binding of Scala learning

Source: Internet
Author: User

1  PackageCom.swust.example2  3Object TraitDemo2extendsapp{4  5    //Abstract class6      Abstract classWriter {7 def writemessage (message:string)8      }9      /**Ten * Inherit this abstract class, and call this abstract method with super One * Scala requires that methods be declared as abstract override A * Override tells Scala to provide an implementation for a known method of the base class - * Abstract indicates that the actual final implementation of this method is provided by the class that mixes this trait -       */ theTrait Uppercasewriterextendswriter{ -         AbstractOverride Def writemessage (message:string) ={ -            Super. Writemessage (message.touppercase) -         } +      } -      /** + * Two things to call Super.writemessage,scala A * 1. Delay binding for this call at * 2. The class required to mix these trait provides the implementation of this method -       */ -Trait Wordfilterwriterextendswriter{ -         AbstractOverride Def writemessage (message:string) ={ -            Super. Writemessage (Message.replace ("stupid", "s-----")) -         } in      } -      classStringwriterdelegateextendswriter{ toVal writer =NewJava.io.StringWriter +         //implement the method of the abstract class without the override -def writemessage (message:string) =writer.write (message) theOverride Def toString (): String =writer.tostring *      } $      //mix trait When creating an instancePanax NotoginsengVal First =Newstringwriterdelegate with Uppercasewriter with Wordfilterwriter -Val last =Newstringwriterdelegate with Wordfilterwriter with Uppercasewriter theFirst.writemessage ("There is no sin except stupidity") +Last.writemessage ("There is no sin except stupidity") A println (first) the println (last) +        -}

The delayed binding of Scala learning

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.