将下划线传递给类型构造函数
Passing Underscore To a Type Constructor
我今天遇到了一个签名如下的方法:
def foo() : Future[_] = { /* some code */ }
我的问题是这里的 return 类型是什么意思?这是否意味着此方法 return 是 Future
而我不关心计算的类型是什么?还是其他原因?
Future[_]
类型就是 the placeholder syntax for existential type:
Future[X] forSome { type X }
所以
def foo(): (Future[X] forSome { type X }) = { /* some code */ }
表示:foo
returns 具有某种未知类型值的 Future
X
。所以,你的解读
"this method returns a Future and I do not care what the type of the computation is"
正确。
我今天遇到了一个签名如下的方法:
def foo() : Future[_] = { /* some code */ }
我的问题是这里的 return 类型是什么意思?这是否意味着此方法 return 是 Future
而我不关心计算的类型是什么?还是其他原因?
Future[_]
类型就是 the placeholder syntax for existential type:
Future[X] forSome { type X }
所以
def foo(): (Future[X] forSome { type X }) = { /* some code */ }
表示:foo
returns 具有某种未知类型值的 Future
X
。所以,你的解读
"this method returns a Future and I do not care what the type of the computation is"
正确。