Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 350
Alexander Arendar Avatar asked May 31 '26 00:05

Alexander Arendar


1 Answers

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.

like image 82
Mario Galic Avatar answered Jun 01 '26 16:06

Mario Galic