J'ai ce code:Scala - comment ne pas appeler une méthode unaire
def +(s: String) = s.headOption
val foo = +("hello")
Lorsque vous essayez de le compiler, je reçois une erreur de compilation:
Error: value unary_+ is not a member of String
val foo = +("hello")
Comment puis-je empêcher le compilateur de insérer un appel à String.unary_-
, mais appeler plutôt la méthode dans la portée?
Il y a un problème pour pourquoi est-il nécessaire de 'this.f (arg)' pour obtenir la conversion implicite 'this' (conversion à quelque chose avec 'f'), pourquoi n'est-ce pas' f (arg) 'assez. Cela pourrait être un bon exemple pourquoi pas. Ou, peut-être qu'ils sont tous les deux un argument pour essayer 'this.expr' avant d'échouer. –