[英]what is the data type of object when passing to another class in scala ? or how to pass an object type as a parameter to another class?
在下面的代碼中,我想將profileobj傳遞給UserActor類,但是我應該為此指定什么類型,如您所見,目前,我將類型設置為Any,但這是行不通的。
case class Profile(i: Int, j: Double)
object Local {
def main(args: Array[String]){
profileobj = new Profile(10, 20)
var k = 30 ;
}
}
val userActor = system.actorOf(Props(new UserActor(profileobj, k)), name = username)
class UserActor(profileobj: Any, k: Int) extends Actor {
var a: Int = profileobj1.i
}
我收到錯誤信息,
value i is not a member of Any
var a: Int = profileobj1.i
如果不是這樣,我還有其他方法可以將此對象傳遞給UserActor類嗎?
它是Local.type
對象的名稱,后跟type關鍵字。
您可以在我的Scala的Types of Types匯編中閱讀有關此內容的更多信息。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.