Reference Java interface static fields in Kotlin

前端 未结 1 1577
我寻月下人不归
我寻月下人不归 2020-12-19 00:29

Can I reference Java interface fields from Kotlin? I have this Java interface:

public interface BaseColumns {
    public static final String _ID = \"_id\";
          


        
相关标签:
1条回答
  • 2020-12-19 00:36

    In Kotlin, unlike Java, static members of interfaces are not derived and cannot be called in subclasses without qualifying the interface name.

    You should reference _ID through BaseColumns: BaseColumns._ID will work.

    This seems to be different for classes: non-qualified name of a base class static member resolves to it, but the member is still not inherited.

    0 讨论(0)
提交回复
热议问题