当前位置:网站首页>Scala trait construction mechanism
Scala trait construction mechanism
2022-06-25 01:03:00 【Jue Niu thunder plough hot blade】
// trait Structural mechanism
// Construction mechanism rules :
// Each trait has only one parameterless constructor
// in other words ,trait There is also construction code , But different from class , A trait cannot have a constructor
//
// Encounter a class inheriting another class 、 And many trait The situation of , When creating an instance of this class , Its constructor executes in the following order :
// 1. The constructor that executes the parent class
// 2. From left to right , Execute sequentially trait Constructor
// 3. If trait Have a father trait, Execute parent first trait Constructor
// 4. If more than one trait Having the same father trait, Then father trait The constructor of can only be initialized once
// 5. Execute subclass constructor
object Trait construction mechanism {
trait Logger {
println(" perform Logger Constructors ")
}
trait MyLogger extends Logger {
println(" perform MyLogger Constructors ")
}
trait TimeLogger extends Logger {
println(" perform TimeLogger Constructors ")
}
class Person {
println(" perform Person Constructors ")
}
class Student extends Person with MyLogger with TimeLogger {
println(" perform Student Constructors ")
}
def main(args: Array[String]): Unit = {
new Student
}
}
边栏推荐
- If the order has not been paid for 30 minutes, it will be automatically cancelled. How can I achieve this?
- Go语言运算符(第8课下)
- Easy to wear - drop down radio
- 2019 summary and 2020 outlook
- QT(36)-rapidjson解析嵌套的json
- Usage of ViewModel and livedata in jetpack
- A small crawler program written by beginners
- Source code analysis the problem that fragments cannot be displayed in the custom ViewGroup
- December 6, 2019 what happens after the browser enters a URL
- 2021-11-05
猜你喜欢

Decoupling pages and components using lifecycle

Add information on the left and add parts on the right of the status bar

不重要的token可以提前停止计算!英伟达提出自适应token的高效视觉Transformer网络A-ViT,提高模型的吞吐量!...

108 pages (40000 words) proposal for future apartment intelligent design platform project (version 2022)

I brush the question I - copy the linked list with random pointer
![[redis realizes seckill service ④] one order for one person, and cannot be purchased repeatedly](/img/75/bc588eb4e54899e93cc7df62e45820.png)
[redis realizes seckill service ④] one order for one person, and cannot be purchased repeatedly

2021-09-12

Custom control - round dot progress bar (imitating one key acceleration in security guard)

Source code analysis the problem that fragments cannot be displayed in the custom ViewGroup

Mobile security tool jar
随机推荐
智能合约安全审计入门篇 —— delegatecall (2)
Leetcode 1248. Statistics of "graceful subarray" (harm, suddenly found that it can only enumerate violently)
Tiktok wallpaper applet v1.0.2 function, new arrival function
大厂高频软件测试面试题和答案都帮你准备好啦,备战金九银十
Sliding window technology based on byte in transport layer
Only positive integers can be entered in the text box
2022熔化焊接与热切割复训题库模拟考试平台操作
How to quickly open traffic master for wechat applet
Jar package merging using Apache ant
Kubernetes 架构核心组件工作原理解析
The drawableleft of the custom textview in kotlin is displayed in the center together with the text
移动安全工具-apktool
Redis + Lua implementation of distributed interface current limiting
The picture of wechat official account can not be displayed normally
Usage of assert
More pictures | explain the Nacos parameters in detail!
Mobile security tool jar
VNC viewer remote connection raspberry pie without display
JSON file of China's provincial boundaries
2022年起重机司机(限桥式起重机)考试题库模拟考试平台操作