Cannot resolve symbol @ReadOnly and @Mutable in Ko

2019-04-16 09:20发布

问题:

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

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

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<>();
    }
}

Thanks in advance.

回答1:

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
    ...
}


标签: java kotlin