Scala briefly -- class and object, scala
Class
In scala, classes are not declared as public. The source file can contain multiple classes, all of which have common visibility. The getter and setter methods are provided for each field, which are called Field Names and field name_, respectively, and can be customized. Note: 1) if the field is private, getter and setter are also private. 2) if the field is val, only the getter method is used. 3) If no getter or setter is required, the field can be declared as private [this]
When the scala field is marked as @ BeanProperty, the Java attribute definition methods getxxx and setxxx are generated.
The class in scala has a primary constructor, which can have any number of auxiliary constructor. The difference between the constructor and other languages is: 1) the name is this 2) must start with a call to a previously defined third-party constructor or master constructor.
The parameters of the main constructor are placed directly after the class name, and all statements in the class definition will be executed. The non-parameter main constructor only executes all statements in the class body. If you define the master constructor as private, you must use the auxiliary constructor to construct the object. In the embedded class, you can useExternal class. this
To access this reference of the external class.
Object
An object has all the characteristics of fatigue, and only cannot provide the constructor parameters. All the places where the singleton object is used can be implemented using objects in scala. 1) as a place to store tool functions or constants 2) efficiently share a single immutable instance 3) when a single instance is needed to coordinate a service
For Classes in Java that have both instance methods and static methods, scala is implemented through classes and companion objects with the same name as classes. Class and its associated objects can access the private properties of each other and must exist in the same source file.
Each scala program must start with the main method of an object, and can also expand the App features. Scala does not have Enumeration types, but the standard library provides an Enumeration helper class for generating Enumeration.