타입이 타입 매개변수를 받지 않음
타입이 타입 매개변수를 받지 않음 (Type Does Not Take Parameters)
타입 매개변수를 받지 않는 타입에 타입 인자를 넣었을 때 나오는 에러예요.
본문
타입 매개변수를 받지 않는 타입에 타입 매개변수를 지정하면 이 에러가 발생해요.
타입 매개변수를 받지 않도록 선언된 타입에 타입 매개변수를 지정한 거예요. 이런 상황에서 주로 나타나요.
- 제네릭이 아닌 타입에 타입 인자를 적용한 경우
- 타입 별칭(type alias)을 그 뒤에 있는 매개변수화된 타입과 혼동한 경우
- 타입 람다(type lambda)가 허용되지 않는 곳에서 F-바운드를 사용한 경우
예시
val x: Int[String] = 42
에러 메시지
-- [E053] Type Error: example.scala:1:7 ----------------------------------------
1 |val x: Int[String] = 42
| ^^^^^^^^^^^
| Int does not take type parameters
|-----------------------------------------------------------------------------
| Explanation (enabled by `-explain`)
|- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| You specified a type parameter Ident(String) for Int, which is not
| declared to take any.
-----------------------------------------------------------------------------
해결 방법
// Remove the type parameters from non-generic types
val x: Int = 42
// Use a type that does accept parameters
val x: List[Int] = List(42)
// Or define your own generic type
class Box[T](value: T)
val x: Box[Int] = Box(42)
더 알아보기
- 제네릭이 아닌 타입에서는 타입 매개변수를 빼고, 매개변수를 받는 타입을 쓰거나 직접 제네릭 타입을 정의하면 돼요.