E122: Imported Twice — 같은 이름이 두 번 import된 경우

E122: Imported Twice — 같은 이름이 두 번 import된 경우

같은 import 줄에서 같은 이름을 두 번 import할 때 발생하는 에러예요.

출처: Scala 3 Reference

본문

같은 import 줄에서 같은 이름을 두 번 import할 때 발생해요.

import 줄마다 각 이름은 한 번만 가져와야 해요. 같은 줄에서 중복 import는 중복일 뿐이라, 아마도 실수로 적은 경우가 대부분이에요.

예시

import scala.collection.mutable.{ArrayBuffer, ArrayBuffer}

에러

-- [E122] Syntax Error: example.scala:1:46 -------------------------------------
1 |import scala.collection.mutable.{ArrayBuffer, ArrayBuffer}
  |                                              ^^^^^^^^^^^
  |                    ArrayBuffer is imported twice on the same import line.

해결 방법

이름을 한 번만 import하면 돼요.

// Import each name only once
import scala.collection.mutable.ArrayBuffer

별칭이 필요하다면 서로 다른 이름을 쓰면 되고요.

// Or if you need aliases, use different names
import scala.collection.mutable.{ArrayBuffer, ArrayBuffer as MutableBuffer}