简体   繁体   English

Kotlin:使用“ val Authority”覆盖名为“ getAuthorities()”的接口方法

[英]Kotlin: Override interface method named 'getAuthorities()' with 'val authorities'

In Kotlin I'm implementing a Java interface that contains method: 在Kotlin中,我实现了一个包含方法的Java接口:

Collection<? extends GrantedAuthority> getAuthorities();

Now, of course I can just go ahead and override the method directly, but I'm wondering if there is a way to implement this with a Kotlin property, along the lines of: 现在,我当然可以直接直接重写该方法了,但是我想知道是否有一种方法可以通过以下方式使用Kotlin属性实现该方法:

/* Broken code, does not compile */
override val authorities = listOf( /* ... */ )

Or does Kotlin simply not support this kind of thing? 还是Kotlin根本不支持这种事情?

No, you cannot replace a method(Behavior), from an interface, with a property. 不可以,您不能使用属性替换接口中的方法(行为)。

Its not possible to override JVM methods with Kotlin properties 无法使用Kotlin属性覆盖JVM方法

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM