簡體   English   中英

IntelliJ 無法識別 Scala 中的 TypeTag

[英]IntelliJ doesn't recognize TypeTag in Scala

我正在嘗試在Scala 中編譯這兩行代碼(使用 Gradle):

import import scala.reflect.runtime.universe._
val typeInt = typeTag[Int]

事實證明,IntelliJ 以某種方式用紅色標記了runtime這個詞。 並向我拋出此錯誤: object runtime is not a member of package reflect one error found

現在,對我來說奇怪的是,當我使用 Scala REPL 時,它發現這個包沒有任何問題

scala> import scala.reflect.runtime.universe._
import scala.reflect.runtime.universe._

scala> val typeInt = typeTag[Int]
val typeInt: reflect.runtime.universe.TypeTag[Int] = TypeTag[Int]

Gradle 的build.gradle文件

plugins {
    id 'java-library'
    id 'scala'
    id 'com.github.maiflai.scalatest' version '0.26'
}

repositories {
    jcenter()
}

dependencies {
    implementation 'org.scala-lang:scala-library:2.13.3'
    implementation 'com.fasterxml.jackson.module:jackson-module-scala_2.13:2.9.9'
    implementation 'com.typesafe:config:1.4.0'
    testCompile 'org.scalamock:scalamock_2.13:4.4.0'
    testCompile 'org.scalatest:scalatest_2.13:3.1.2'
    testRuntimeOnly 'com.vladsch.flexmark:flexmark-all:0.35.10'
}

版本

  • IntelliJ IDEA - 社區- 版本 2020.2.3
  • JDK - 版本 14.0.1
  • macOS Catalina - 版本 10.15.7
  • Scala - 版本 2.13.3
  • Gradle - 版本 6.7

根據你的build.gradle你沒有添加scala-reflect依賴

https://mvnrepository.com/artifact/org.scala-lang/scala-reflect/2.13.3

如果你想使用 Scala 反射, scala-library是不夠的。

嘗試添加scala-reflect

implementation 'org.scala-lang:scala-reflect:2.13.3'

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM