我想编写一个scala方法,可以使用RuntimeException的任何子代。我有它但它不编译。代码有什么问题?
def testme(e: RuntimeException): String = {
case e:BadRequestException=> "bad request"
case e: IllegalArgumentException=>"illegal argument"
}
我收到以下错误
missing parameter type for expanded function
[error] The argument types of an anonymous function must be fully known. (SLS 8.5)
[error] Expected type was: String
[error] def testme(e: RuntimeException): String = {
[error] ^
[error] one error found
[error] (playWeb/compile:compileIncremental) Compilation failed
[error] Total time: 5 s, completed Sep 21, 2017 2:45:09 PM
答案 0 :(得分:2)
您必须指定匹配的内容,例如添加def testme(e: RuntimeException): String = e match {
case e:BadRequestException=> "bad request"
case e: IllegalArgumentException=>"illegal argument"
}
:
from ..parser.parser import Parser