2016-05-31 60 views
1

为什么我有这个错误?scala集,对重载定义的歧义引用

Error:(5, 18) ambiguous reference to overloaded definition, both method startsWith in class String of type (x$1: String)Boolean and method startsWith in class String of type (x$1: String, x$2: Int)Boolean match expected type ? fruit filter (_.startsWith == "ap")

VAL水果=集( “应用程序”, “B”, “C”)

水果滤波器(_.startsWith == “AP”)

回答

6

您正在尝试使用语法不正确。 startsWithString方法接受字符串作为参数并返回布尔值。所以正确的用法是:

fruit filter (_.startsWith("ap"))