Kotlin: Cannot access built-in declaration 'kotlin.Boolean'. Ensure that you have a dependency on the Kotlin standard library
IntelliJ IDEA 2023.1.2 (Ultimate Edition)
Build #IU-231.9011.34, built on May 16, 2023
Licensed to signup scooter
You have a perpetual fallback license for this version.
Subscription is active until August 1, 2025.
Runtime version: 17.0.6+10-b829.9 amd64
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o.
Windows 11.0
GC: G1 Young Generation, G1 Old Generation
Memory: 1024M
Cores: 8
Non-Bundled Plugins:
com.tyrfing.plugin (1.6.5)
Pythonid (231.9011.34)
cn.cloud.auto.restful.tool (1.4.5)
Kotlin: 231-1.8.21-IJ9011.34
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-stdlib-jdk8</artifactId>
<!-- <version>1.5.0</version>-->
<!-- <version>1.6.0</version>-->
<!-- <version>1.6.21</version>-->
<!-- <version>1.9.0</version>-->
<version>1.8.0</version>
</dependency>
不知道你这个问题是否已经解决, 如果还没有解决的话:Boolean型只有两个值 true false,大小为1B
和Java的要求一致,Kotlin中的布尔型也不能实现与其他类型的自动转换,这就要求我们必须在判断条件处必须要写一个逻辑表达式(即可判断真假的式子)
回答:
这个问题可能是由于项目中的某个部分在导入没有的库或导入库的位置有误。Kotlin中的'kotlin.Boolean'是Kotlin的内置类型之一,因此不能被导入。建议先检查项目中的依赖,确认是否导入了Kotlin库以及版本是否正确。
同时,如果您正在使用IDE,如IntelliJ IDEA,可以尝试清理和重建项目。如果问题仍然存在,可能需要检查代码中是否有其他明显的问题或语法错误,并尝试更详细地描述问题或提供代码示例,以便更好地解决问题。
下面是代码示例:
import kotlin.Boolean // 导入kotlin.Boolean库,会提示'kotlin.Boolean'不可见
fun main() {
val flag: Boolean = true // 编译器会提示错误
}
应该修改为:
fun main() {
val flag: kotlin.Boolean = true // 使用全限定名称,解决访问问题
}