Search code examples
scalascalatest

Why method is parameterized while type parameter is never used?


In ScalaTest there is a org.scalatest.selenium.WebBrowser trait which provides this method:

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.")
    }

I am curious why this method is parameterized when the type parameter T is not used in implementation. Documentation does not say anything on this regard.

Could you clarify?


Solution

  • According to Semmle:

    An unused type parameter will have no effect and always be inferred to Nothing.

    It also provides the following recommendation:

    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.