I think that the title sums it up. But after a lot of search for this, never found anything related.
I’m using Kotlin in Android projects for the past couple of months and I believe that I found a bug/unexpected behavior.
Consider the following structure in some Java Code Android Library:
interface ConnectionCallback{
//some methods
}
public interface JsonResponseCallback extends ConnectionCallback{
//some other methods
}
Using this library through a maven repo, in my Kotlin file:
someRequest.post(object: JsonResponseCallback{
// override methods
}
I get absolutely no compile warning or errors. But when running that code, I get IllegalAccessException, and a message that says that I’m trying to access the super interface ConnectionCallback, which I’ve never explicitly wrote.
These classes had always been used in our team projects, and we never had any IllegalAccess problems when writing in Java.
Before accessing the library source code and seeing that the super class was declared as package-private, I tried to get an JsonResponseCallback instance from a Java declared function, something like:
Class A.java
static main JsonResponseCallback instantiateJsonCallback(SomeParameters params){
return new JsonResponseCallback{
//override them methods
};
}
Class B.kt
someRequest.post(A.instantiateJsonCallback(params))
It didn’t work either.
But when calling the SomeConnection.post(JsonResponseCallback) method through Java, it works just as It has always worked.
someConnection.post(new JsonResponseCallback(){
//@Overrides, it works!!
});
After a while, I’ve fixed it by going to the library source code and publishing a hotfix, changing the super interface ConnectionCallback visibility to public.