Kotlin无法调用到Java中定义的interface类的问题“Interface is inaccessible declaration of ‘..‘ appears in /data/app”

遇到了一个报错:
Interface is inaccessible declaration of ‘…’ appears in /data/app

错误代码:

interface InitConnectServiceCallback{
        void onServiceConnected(boolean result);
    }
public void setInitConnectServiceCallback(InitConnectServiceCallback initConnectServiceCallback) {
        this.initConnectServiceCallback = initConnectServiceCallback;
    }

Java中默认的方法和变量默认是protected的修饰,但是kotlin中却无法调用protected修饰的方法。

所以只需要在interface前面加上public的修饰符就好了

修改后的代码:

 public interface InitConnectServiceCallback{
        void onServiceConnected(boolean result);
    }

你可能感兴趣的:(java,kotlin,android)