0
我非常新Scala中遇到的奇怪的代码片段:它构造函数重载吗?
class EndpointMapper[A](m: Method, e: Endpoint[A]) extends Endpoint[A] { self =>
/**
* Maps this endpoint to either `A => Output[B]` or `A => Future[Output[B]]`.
*/
final def apply(mapper: Mapper[A]): Endpoint[mapper.Out] = mapper(self)
final def apply(input: Input): Endpoint.Result[A] =
if (input.request.method == m) e(input)
else EndpointResult.Skipped
final override def toString: String = s"${ m.toString.toUpperCase } /${ e.toString }"
}
这是一类,这样我就可以创建它的一个实例。 apply
怎么样?
我可以使用EndpointMapper(mapper)
就像调用apply
方法的函数吗?
如何区分两个应用程序或编译器如何知道应该调用哪个apply
?