Big Data series Cultivation-scala Course 03

Source: Internet
Author: User

Preface

Work today to see a lot about the front js,jquery, Bootstrap.js and Springmvc see vaguely, after all, rarely to learn the front-end technology, all see a bit sleepy, good to see more, go home also began to learn about the Scala related courses, experiment every day to stick to big data related things, what will become after a year ...... Look forward to ..., and today goes on yesterday's course.

Scala Insider in real-class practical explanation

Inside the Scala Insider class: Inside the Scala class to access the external class directly to the external class to the inner class, let itself access, the inner class also needs to be instantiated, and there are many differences in Java, the inner class can access the outer class arbitrary member variable and cannot be a static variable

Scala Insider classes: Implementing internal classes to access external classes

Object Scalaouter {def main (args:array[string]): Unit={val Outer1=NewOuter ("Spark"); Val Outer2=NewOuter ("Hadoop") Val Inner1=NewOuter1. Inner ("Scala") Val Inner2=NewOuter2. Inner ("Java") Inner1.foo (inner1) Inner2.foo (Inner2)} }classOuter (Val name:string) {//In Scala, the inner class accesses the outer class directly to the inner class, giving it its own access, and the inner class needs to be instantiated.Outer =classInner (Val name:string) {def foo (b:inner)=println ("Outer:" +outer.name + "Inner:" +b.name)}}
Scala Singleton object, associated object actual combat

Scala Singleton: A singleton object can directly access methods and variables in public, similar to Java static classes

Scala companion object code Combat: The associated object is that there is a class with this object name, parameters are the same, this class can access its associated objects all the variables and methods (private can)

Object Scalaobject {def main (args:array[string]): Unit= {    //University.studentno, this will be an error .println (University.newstudenno) println (University.newstudenno)} }//The object objects in Scala are like static classes in JavaObject University {Privatevar Studentno = 0//Private variables are not externally accessibledef Newstudenno ={Studentno+ = 1Studentno//the last variable of the function is the return value  }}//Associated Classclassuniversity{val ID=University.newstudennoPrivatevar number =0def aclass (number:int) { This. number + =Number }}
a detailed description of apply in Scala

Application in Objec: Apply method can be used in class and object, you can instantiate class in the associated object, thus calling methods in the class

Application in class: After the class is instantiated, the object () can call the Apply method

Object Applyops {def main (args:array[string]): Unit= {//val applytest = Applyop ()//You can access the methods in the associated object by accessing the methods in the class directly with the associated object .//Applytest.haveatryvar B =NewApplyop () println (b ())}}//associated objects of the Applyop classObject applyop{def apply ()={println ("Object Applyop")    NewAPPLYOP}}//the associated class of the Applyop objectclassapplyop{def apply ()={println ("Class Applyop")} def haveatry{println ("A try on apply")  }}

I hope you have a lot of advice, thank

Video sharing Address: Http://pan.baidu.com/s/1pJ9n3JH

Big Data series Cultivation-scala Course 03

Related Article

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.