我有一个返回类型复杂的方法,我想要一个函数,该函数将这个方法的结果作为参数。是否可以为方法的返回类型创建别名?类似于 C++ 中的 typeof
例如
object Obj {
def method(x:Int) = 1 to x
type ReturnType = ???
//possible solution if i know a parameter for which the method won't fail
val x = method(1)
type ReturnType = x.type
//another possible solution, I don't need a parameter that won't fail
//the method but i still think there is a better way
lazy val x = method(1)
type ReturnType = x.type
//I would then like to have a function which takes ReturnType as a parameter
def doit(t:ReturnType) = Unit
}
问题是编译器知道类型,但我不知道如何从他那里得到它。