Scala中的内部类

时间:2015-07-19 16:52:53

标签: scala

为什么这个val aamir = chatter.Member("abc")行显示编译时错误?

package com.aamir.Classes
import scala.collection.mutable.ArrayBuffer


object Program7 extends App {

val chatter = new Network
val fred = chatter.join("Fred")
val wilma = chatter.join("wilma")
fred.contacts += wilma

val myFace = new Network
val barney = myFace.join("barney")

 val aamir =  chatter.Member("abc")

}

class Network {

    class Member(val name:String) {

    val contacts = new ArrayBuffer[Member]

  }

  private val members = new ArrayBuffer[Member]

  def join(name: String) = {

     val m = new Member(name)
     members += m
     m
  }
}

1 个答案:

答案 0 :(得分:2)

我很确定它应该是

val aamir = new chatter.Member("abc")

因为会员是一个班级,而不是一个功能