本文介绍了无法在Kotlin 1.1.0编译中解析符号@ReadOnly和@Mutable的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在使用Kotlin 1.1.0进行编译时,出现错误无法解析符号ReadOnly"和无法解析符号Mutable". @ReadOnly和@Mutable在Kotlin 1.1.0中不可用吗?以下是示例代码.

I got errors "Cannot resolve symbol ReadOnly" and "Cannot resolve symbole Mutable" in compiling with Kotlin 1.1.0. Is @ReadOnly and @Mutable not available with Kotlin 1.1.0? The following is a sample code.

SampleList.java Kotlin 1.0.7

SampleList.java Kotlin 1.0.7

import org.jetbrains.annotations.Mutable;
import org.jetbrains.annotations.ReadOnly;

import java.util.ArrayList;
import java.util.List;

public class SampleList {
    @ReadOnly // Can resolve symbol 'ReadOnly'
    public static List<Integer> getReadOnlyList() {
        return new ArrayList<>();
    }

    @Mutable // Can resolve symbol 'Mutable'
    public static List<Integer> getMutableList() {
        return new ArrayList<>();
    }
}

SampleList.java Kotlin 1.1.0

SampleList.java Kotlin 1.1.0

import org.jetbrains.annotations.Mutable;
import org.jetbrains.annotations.ReadOnly;

import java.util.ArrayList;
import java.util.List;

public class SampleList {
    @ReadOnly // Cannot resolve symbol 'ReadOnly'
    public static List<Integer> getReadOnlyList() {
        return new ArrayList<>();
    }

    @Mutable // Cannot resolve symbol 'Mutable'
    public static List<Integer> getMutableList() {
        return new ArrayList<>();
    }
}

谢谢.

推荐答案

对不起.添加启用了 @Mutable @ReadOnly kotlin编译器. build.gradle的设置如下.

I'm sorry. Adding kotlin-compiler enabled @Mutable and @ReadOnly. The settings of build.gradle are as follows.

// build.gradle
dependencies {
    compile "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"
    compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
    compile "org.jetbrains.kotlin:kotlin-compiler:$kotlin_version" // Added
    ...
}

这篇关于无法在Kotlin 1.1.0编译中解析符号@ReadOnly和@Mutable的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-03 05:48