在 ScalaTest 中有一个 org.scalatest.selenium.WebBrowser
trait 提供了这个方法:
def executeScript[T](script: String, args: AnyRef*)(implicit driver: WebDriver): AnyRef =
driver match {
case executor: JavascriptExecutor => executor.executeScript(script, args.toArray : _*)
case _ => throw new UnsupportedOperationException("Web driver " + driver.getClass.getName + " does not support javascript execution.")
}
我很好奇为什么在实现中没有使用类型参数T
时,这个方法被参数化了。文档没有说明这方面的任何内容。
你能澄清一下吗?
最佳答案
根据 Semmle :
An unused type parameter will have no effect and always be inferred to
Nothing
.
它还提供了以下建议:
Unused type parameters have no effect on your program beyond confusing the reader and cluttering up the definition... Remove the type parameter if it is genuinely unused, or add a use if it is supposed to be used.
关于scala - 为什么方法参数化而类型参数从不使用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49922896/