"Spark Asia-Pacific Research series" Spark Combat Master Road-2nd Chapter hands-on Scala 2nd bar (3)

Source: Internet
Author: User

5. Apply method and Singleton object in Scala  

to create a new class:

As an additional point, the methods placed in object objects are static methods, as follows:

Next look at the use of the Apply method:

The above code always when we use "val a = Applytest ()" will cause the call of the Apply method and return the value of the method call, that is, the instantiated object of the applytest.

C The lass can also be used by the Apply method, as shown in the following ways:

Because the methods and properties in object are static, this is the ideal vector for singleton objects, as shown in the example code:

In other words, object itself is a singleton!

"Spark Asia-Pacific Research series" Spark Combat Master Road-2nd Chapter hands-on Scala 2nd bar (3)

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.