[英]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.