将对象传递到scala函数
我创建了一个简单的对象,并将它传递给函数,然后将该函数用于集合,但它不起作用。你能看出代码有什么问题吗将对象传递到scala函数,scala,Scala,我创建了一个简单的对象,并将它传递给函数,然后将该函数用于集合,但它不起作用。你能看出代码有什么问题吗 class testObj(s: String) { val st = s; } val x = List("michael", "peter", "test").map(a => new testObj(a)) def tempFunc(p: testObj) :testObj = { p} x.map(y => tempFunc(y)) The error is
class testObj(s: String) {
val st = s;
}
val x = List("michael", "peter", "test").map(a => new testObj(a))
def tempFunc(p: testObj) :testObj = { p}
x.map(y => tempFunc(y))
The error is
console>:19: error: type mismatch;
found : testObj
required: testObj
x.map(y => tempFunc(y))
谢谢这应该运行良好,没有错误(只是执行了它)。您确定您正在执行这段代码吗?似乎有效:可能这是scalac错误-您使用的是什么版本的scala?您的代码在REPL for scala
2.11.0