Scala Fun Question 15

Source: Internet
Author: User

True or False?


Class C val x1, x2 = new C val y1 @ y2 = new C println (x1 = x2) println (y1 = = y2)



























Explain

Val P1, p2 = new C is val p1 = new C; val P2 = shorthand for new C

Val [email protected] = new C is a pattern binder


Explanation


According to the SLS (§4.1), a value definition val p1, ..., pn:t = e is a shorthand for the sequence of value Defini tions val p1:t = e; ...; Val pn:t = e. This means, example the expression new C is evaluated twice and therefore x1 = = x2 is False.


The second value definition is a pattern binder which are defined in sls§8.1.3. A pattern binder [email protected] consists of a pattern variable x and a pattern p. In we case the pattern P was a variable pattern which matches any value and binds the variable name (in we case y2) to th At value. The pattern binder binds that value also to the pattern variable y1. As the same value is bound to both variables Y1 and y2, the expression y1 = = Y2 is true.


Scala Fun Question 15

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.