-
TypeTag, ClassTagscala/basic 2025. 4. 22. 21:54
TypeTag
import scala.reflect.runtime.universe._ def printType[T: TypeTag](value: T): Unit = { println(s"Type: ${typeOf[T]}") } printType(42) // 출력: Type: Int printType("Hello") // 출력: Type: String
ClassTag
import scala.reflect.ClassTag def createArray[T: ClassTag](size: Int): Array[T] = { new Array[T](size) } val intArray = createArray[Int](5) // Int 배열 생성 val strArray = createArray[String](5) // String 배열 생성
'scala > basic' 카테고리의 다른 글
Semaphore 를 사용해 최대 maxConcurrent 개의 Future만 실행되도록 제한 (0) 2025.03.13 Tagless Final (0) 2024.11.19 method 이름은 같은데 param, return 타입을 다르게 구현하기 (0) 2024.03.07 Blocking Future (0) 2023.02.13 Environment, Property variable 읽기 (0) 2023.02.03