0

I have the following 2 methods:

def callAlpha = call[T](Constants.Alpha)(_: String)(_: T => T) def call[T](symbol: String)(caller: String)(op: T => T)(implicit ct: ClassTag[T]): String = { // some code } 

Eclipse complains about the use of generics in the first method, but not in the second. Why is this?

2
  • 1
    Is there a declaration type ->[A, B] = ... or trait ->[A, B] { ... } somewhere in scope, or was this supposed to be T => T? Commented Feb 12, 2018 at 22:39
  • argh it was supposed to be T => T Commented Feb 12, 2018 at 22:49

2 Answers 2

3

In the second method you include a type parameter definition ([T] which immediately follows the method name). This declares a type parameter named T (you can name it however you want) which can then be used in the method's input arguments, output type, and implementation.

The first method is missing this definition - it attempts to use a type named T without declaring such a type: the method name (callAlpha) is not followed by a similar type parameter definition and therefore the method body (call[T](Constants.Alpha)(_: String)(_: T -> T)) cannot use it.

The fix can be simple - define T for the first method too:

def callAlpha[T] = call[T](Constants.Alpha)(_: String)(_: T => T) 
Sign up to request clarification or add additional context in comments.

Comments

2

Because in

def callAlpha = call[T](Constants.Alpha)(_: String)(_: T => T) 

there is an unbound type variable T on the right hand side.

You probably meant:

def callAlpha[T] = call(Constants.Alpha)(_: String)(_: T => T) 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.