Today, Mr. Wang studied the function of pattern matching in Scala from the source point of view. Let's look at this pattern match in the source code:
From the code we can see that case Registerworker (Id,workerhost,........) {} Here is a pattern match, and our pattern-matching class registerworker before it is defined, such as:
We can see that our pattern matching class is already defined, and when our master receives a message from the worker, it makes a pattern match:
。
There is also a knowledge point where we can find that when we do pattern matching, we do not use the new method to create a new instance, but instead use the Registerworker (ID,.....) directly. And here, we are using the associated application method of the class. When a pattern match is made, the Unapply method is used to parse the content that the instance passes over.
Share more of the Scala resources:
Baidu Cloud Disk: http://pan.baidu.com/s/1gd7133t
Micro Cloud Disk: http://share.weiyun.com/047efd6cc76d6c0cb21605cfaa88c416
360 Cloud Disk: Http://yunpan.cn/cQN9gvcKXe26M (extract code: 13CD)
Information from DT Big Data Dream Factory public account: Dt_spark
Follow the account for more information about Scala learning
74th: Thinking about pattern matching in Scala from the perspective of Spark source