原创文章,转载请注明出处!

原文地址: http://www.ptbird.cn/2016/07/19/scala-chuji-demo-07/

There I am,in the world more exciting!

by postbird

www.ptbird.cn


07内部类


 
package com.ptbird.scala /** * Created by postbird on 2016/5/25. */ class Outer(val name: String) { outer => //内部类 class Inner(val name: String) { def foo(b: Inner) = println("Outer " + outer.name + " Inner " + b.name) } } object ClassTest3 { def main(args: Array[String]): Unit = { val outer1 = new Outer("Spark") val outer2 = new Outer("Hadoop") val inner1 = new outer1.Inner("admin") val inner2 =new outer2.Inner("root") inner1.foo(inner1) //不能使用 inner1.foo(inner2) inner2.foo(inner2) //内部类隶属于外部类的实例而不是属于外部类 } }