Ben scala aşağıdaki örtük dönüştürme yazın:Bu tür örtük dönüştürme neden yasa dışı?
implicit def strToInt2(str: String):Int = {
str.toInt
}
Ama bu derleme hatası yükselir: Ben dönüş türü kaldırırsanız
<console>:9: error: type mismatch;
found : str.type (with underlying type String)
required: ?{val toInt: ?}
Note that implicit conversions are not applicable because they are ambiguous:
both method augmentString in object Predef of type (x: String)scala.collection.
immutable.StringOps
and method toi in object $iw of type (str: String)Int
are possible conversion functions from str.type to ?{val toInt: ?}
str.toInt
^
, sadece bu gibi beyan:
implicit def strToInt2(str: String) = {
str.toInt
}
Başarılı bir şekilde derler. Kimse bana ikisi arasındaki farkın ne olduğunu söyleyebilir mi?
Kesin cevabı bilmiyorum, ama sanırım Predef'de bir örtük dönüştürme dizesi var. Bu yüzden, bu türlerin yeni dönüşümünü eklemek bazı şeyleri belirsizleştirir. – dmitry