Alexander Arendar
Alexander Arendar

Reputation: 3425

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?

Upvotes: 3

Views: 139

Answers (1)

Mario Galic
Mario Galic

Reputation: 48420

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.

Upvotes: 1

Related Questions