scala java混合_Scala特性混合
scala java混合
Scala | 特性混合 (Scala | Trait Mixins )
In Scala, the number of traits can be extended using a class or an abstract class. This is known as Trait Mixins. For extending, only traits, the blend of traits, class or abstract class are valid.
If the sequence of Trait Mixins is not maintained, an error is thrown by the compiler. It is used in composing a class. As multiple traits can be inherited.
在Scala中,可以使用類或抽象類擴(kuò)展特征的數(shù)量。 這被稱為特質(zhì)混合 。 對于擴(kuò)展,只有特征,特征,類或抽象類的混合才有效。
如果未保留“ 特性混合”的順序,則編譯器將引發(fā)錯誤。 它用于組成一個類。 由于可以繼承多個特征。
Let's look at a few examples to understand the topic better,
讓我們看一些例子,以更好地理解該主題,
Example 1: Extending abstract class with a trait
示例1:使用特征擴(kuò)展抽象類
trait Bike { def Bike() ; } abstract class Speed { def Speed() ; } class myBike extends Speed with Bike { def Bike() { println("Harley Davidson Iron 883") ;} def Speed() { println("Max Speed : 170 KmpH") ;} } object myObject { def main(args:Array[String]) { val newbike = new myBike() ;newbike.Bike() ;newbike.Speed() ;} }Output
輸出量
Harley Davidson Iron 883 Max Speed : 170 KmpHExample 2: Extending abstract class without a trait
示例2:擴(kuò)展不帶特征的抽象類
trait Bike { def Bike() ; } abstract class Speed{ def Speed() ; } class myBike extends Speed { def Bike() { println("Harley Davidson Iron 883") ;} def Speed() { println("Max Speed : 170 KmpH") ;} } object myObject { def main(args:Array[String]) { val newbike = new myBike() with Bike;newbike.Bike() ;newbike.Speed() ;} }Output
輸出量
Harley Davidson Iron 883 Max Speed : 170 KmpH翻譯自: https://www.includehelp.com/scala/trait-mixins.aspx
scala java混合
總結(jié)
以上是生活随笔為你收集整理的scala java混合_Scala特性混合的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 最长公共前缀_最长的公共前缀
- 下一篇: Sys.WORD_SIZE Julia中