Got a quick question about using a Java API from K...
# announcements
t
Got a quick question about using a Java API from Kotlin. The API in question is the Cast API from Google that is defined in a strange way.
Copy code
public final class Cast {
public static final Cast.CastApi CastApi;

    private Cast() {
    }

    public interface CastApi {
   }
}
Accessing the static final field from Kotlin seems impossible AS always think I'm referring to the interface and not the field, is there any trick for that?
e
Hm… it works for me:
Copy code
val api: Cast.CastApi = Cast.CastApi
It resolves to type at the left and to static variable at the right.
t
Hum thanks for the workaround 🙂 I was doing like before in Java and directly calling
Cast.CastApi.function()
and that does not work. Using a val works and allows me to remove a Java file that I used as a bridge.
e
I now see what is the problem! You don’t have to use a variable. You can also add an import for
Cast.CastApi
and the a short name
CastApi
would resolve to a variable so that you can use its methods with
CastApi.method()
t
Import hack works too 🙂 Should I raise an issue for the default use case, or is somewhat normal?
e
It is so by design.
👍 2