我最近在使用 Spring Security 进行开发时遇到了一个问题。它有一个GrantedAuthority
带有以下签名的接口:
public interface GrantedAuthority extends Serializable, Comparable
而对于 Java 1.5 及更高版本,该接口Comparable
采用类型参数T
,在 Spring Security 库中省略了该参数(显然是为了兼容 JVM 1.4)。
所以我试图GrantedAuthority
在 Scala 中实现。
class Role extends GrantedAuthority {
. . .
def compareTo(obj: Any): Int = obj match {
case (r: Role) => r.toString.compareTo(this.toString)
case _ => -1
}
}
它不编译:
error: class Role needs to be abstract, since method compareTo in trait Comparable of type (T)Int is not defined
如何在 Scala 中实现这样的接口?