[英]Is it possible to override Java getter (method) with Kotlin val (property)?
[英]Kotlin: Override interface method named 'getAuthorities()' with 'val authorities'
在Kotlin中,我實現了一個包含方法的Java接口:
Collection<? extends GrantedAuthority> getAuthorities();
現在,我當然可以直接直接重寫該方法了,但是我想知道是否有一種方法可以通過以下方式使用Kotlin屬性實現該方法:
/* Broken code, does not compile */
override val authorities = listOf( /* ... */ )
還是Kotlin根本不支持這種事情?
不可以,您不能使用屬性替換接口中的方法(行為)。
無法使用Kotlin屬性覆蓋JVM方法
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.