2016-05-31 40 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"))