Type與Class
點選(此處)摺疊或開啟
-
class Spark
-
trait Hadoop
-
object Flink //單例
-
class Java{
-
class Scala
-
}
-
object Type_Advanced {
-
-
def main(args: Array[String]) {
-
println(typeOf[Spark]) //結果:com.dt.scala.bestpractice.Spark
-
println(classOf[Spark]) //Class[_ <: Spark],結果:class com.dt.scala.bestpractice.Spark
-
- val spark = new Spark
-
println(spark.getClass); //結果:class com.dt.scala.bestpractice.Spark
-
-
println(classOf[Hadoop]) //結果:interface com.dt.scala.bestpractice.Hadoop
-
println(typeOf[Hadoop]) //結果:com.dt.scala.bestpractice.Hadoop
-
-
println(Flink.getClass) //結果:class com.dt.scala.bestpractice.Flink$,這個$說明,在Scala中,object背後也是有類的
-
// println(classOf[Flink])
-
-
val java1 = new Java
-
val java2 = new Java
-
val scala1 = new java1.Scala
-
val scala2 = new java2.Scala
-
println(scala1.getClass) //結果:class com.dt.scala.bestpractice.Java$Scala
-
println(scala2.getClass) //結果:class com.dt.scala.bestpractice.Java$Scala
-
println(typeOf[java1.Scala] == typeOf[java2.Scala]) //false
-
println(typeOf[java1.Scala]) //結果:java1.Scala
-
println(typeOf[java2.Scala]) //結果:java2.Scala
-
- //type是更詳細的資訊,而class是更抽象的資訊
-
-
println(classOf[List[Int]] == classOf[List[String]]) //true
-
println(typeOf[List[Int]] == typeOf[List[String]]) //false
- println(classOf[List[Int]]) //class scala.collection.immutable.List
- println(classOf[List[String]]) //class scala.collection.immutable.List
- println(typeOf[List[Int]]) //scala.List[Int]
-
println(typeOf[List[String]]) //scala.List[String]
-
}
-
- }
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/28912557/viewspace-2058807/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- error: '[class name]' does not name a typeError
- TypeScript中,type、interface、class的區別TypeScript
- variable: Type 與 Type variable
- 條款 19:設計 class 猶如設計 type
- 條款19 設計class 猶如設計type
- this與class(原型)原型
- SAP WM Storage Type Search配置裡的Storage Class & WPC標記
- The type XXX cannot be resolved.It is indirectly referenced from required .classUI
- Struct與Class辨析Struct
- class與dex檔案
- Vue Class與Style繫結Vue
- vue Class 與 Style 繫結Vue
- vue 的 class 與 style 使用Vue
- Object與Class的關係Object
- class語法與繼承繼承
- Pycharm,Python 3 與 Type HintsPyCharmPython
- Android layer type與WebView白屏AndroidWebView
- Scala的Infix Type與Self Types
- Android bugs——NoSuchFieldError: No static field btn_press3 of type I in class Lcom/hyphenate/helpdesAndroidErrorS3
- iOS攻防:class-dump 與 Dumpdecrypted 使用iOS
- class與classloader的getResourceAsStream區別
- 小程式與Vue對比·class與style繫結Vue
- Unable to load bean: type:org.apache.struts2.views.gxp.inject.InjectedObjectContainer class:org.apacBeanApacheViewObjectAI
- :first-child與:first-of-type 區別
- 【CSS】nth-child 與 nth-of-type辨析CSS
- input[type="checkbox"]與label對齊
- cannot convert (type interface {}) to type int: need type assertion
- 熱修復與外掛化基礎——dex與class
- Web前端——Class與ID的使用規範Web前端
- Value Type vs Reference Type in SwiftSwift
- iOS[super class]和[self class]iOS
- 理解 Swift 中的元型別:.Type 與 .selfSwift型別
- Class.isAssignableFrom與instanceof的區別
- CSS中的class與id區別及用法CSS
- CSS ID選擇器與CLASS選擇器CSS
- Typescript的interface、class和abstract classTypeScript
- E:last-child與E:last-of-type區別AST
- 【乾貨】TypeScript 實戰之 extends、infer 與 dva typeTypeScript