-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
46 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package ScalaAdvance.Generic1 | ||
|
||
// https://www.bilibili.com/video/BV12N411R726?p=272 | ||
|
||
object demo1 extends App { | ||
// run | ||
val int_msg = new IntMessage[Int](10) | ||
println("int_msg = " + int_msg) | ||
|
||
val str_msg = new StrMessage[String]("hola") | ||
println("str_msg = " + str_msg) | ||
} | ||
|
||
abstract class Message[T](s:T){ | ||
// method | ||
def get() = s | ||
} | ||
|
||
class IntMessage[Int](v:Int) extends Message(v) | ||
class StrMessage[String](v:String) extends Message(v) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package ScalaAdvance.Generic1 | ||
|
||
// https://www.bilibili.com/video/BV12N411R726?p=272 | ||
|
||
import ScalaAdvance.Generic1.SeasonEnum | ||
|
||
object demo2 { | ||
def main(args: Array[String]): Unit = { | ||
// run | ||
// TODO : fix below | ||
//val class01 = new EnglishClass[SeasonEnum, String, String](SeasonEnum.spring, "0001","intro") | ||
|
||
//val class02 = new EnglishClass[SeasonEnum, String, String](SeasonEnum.summer, "002","advanced") | ||
} | ||
} | ||
|
||
// val classSeason:A -> will make the input arg as READ ONLY arg | ||
class EnglishClass[A,B,C](val classSeason:A, val className:B, val classType:C) | ||
|
||
// season is an enumerate class | ||
// https://github.com/yennanliu/utility_Scala/blob/master/src/main/scala/ScalaBasic/EnumerationDemo.scala | ||
class SeasonEnum extends Enumeration { | ||
type seasonEnum = Value | ||
val spring, autumn, summer, winter = Value | ||
} |