Is there a manner to import a specific method signature?
def test() {
lazy val log = LoggerFactory.getLogger("AndroidProxy")
import log.{error, debug, info, trace}
trace("This is a test")
trace "This is also" // <- This line will not compile
}
Perhaps it’s not possible, but my primary goal is to allow this without adding in a new method. I’ve tried these to no avail
import log.{error => error(_:String)}
import log.{error(x: String) => error(x)}
I suppose the primary challenge is that all of the methods take one argument. I can call no-argument methods without (), and I can create a chain of method calls that omits the .’s e.g. foo getX toString, but I don’t know how to create an arity-1 call automatically
This is a followup to this question.
The issue with the code:
is not that you’re somehow importing too many overloaded variants of
trace– it’s that you can’t use Scala’s infix notation this way. An expression like:is interpreted as a “Postfix Operation” (see section 6.12.2 of the Scala Language Specification), equivalent to the call:
So your code would be equivalent to:
which is of course a compile error.
If you instead use an “Infix Operation” of the form
e1 op e2(section 6.12.3 of the Scala Language Specification), then there aren’t any problems even if the method is overloaded: