我正在编写CRaSH插件,在Java中看起来像
public class AuthPlugin extends CRaSHPlugin<AuthenticationPlugin> implements AuthenticationPlugin<String> {
@Override
public String getName() {
return "auth";
}
@Override
public Class<String> getCredentialType() {
return String.class;
}
@Override
public boolean authenticate(String username, String credential) throws Exception {
System.out.println("authenticate " + username + " : " + credential);
return false;
}
@Override
public void init() {
System.out.println("init");
}
@Override
public AuthenticationPlugin getImplementation() {
return this;
}
}
但是,我想在Kotlin表达这个课程。问题是AuthenticationPlugin
,generic parameter。省略是导致Kotlin编译失败,所以我使用了星形投影,比如
class AuthPlugin : CRaSHPlugin<AuthenticationPlugin<*>>(), AuthenticationPlugin<String> {
override fun getImplementation(): AuthenticationPlugin<String> = this
override fun getName(): String = "auth"
override fun authenticate(username: String?, credential: String?): Boolean {
println("authenticate ${username}, ${credential}")
return true
}
override fun getCredentialType(): Class<String> = String::class.java
}
编译很好,但不幸的是,CRaSH似乎使用它自己的加载插件的方式,我得到了运行时异常
Caused by: java.lang.UnsupportedOperationException: Type resolution of org.crsh.auth.AuthenticationPlugin<?> not yet implemented
at org.crsh.util.Utils.resolveToClass(Utils.java:576) ~[crash.shell-85c8d21173b71a0275b599a3a4444723dd64c6af.jar:?]
at org.crsh.util.Utils.resolveToClass(Utils.java:560) ~[crash.shell-85c8d21173b71a0275b599a3a4444723dd64c6af.jar:?]
at org.crsh.plugin.CRaSHPlugin.<init>(CRaSHPlugin.java:59) ~[crash.shell-85c8d21173b71a0275b599a3a4444723dd64c6af.jar:?]
确实,resolveToClass()
的输入是&#34; Class @ interface org.crsh.auth.AuthenticationPlugin&#34;对于Java版本,而对于Kotlin,它的&#34; ParametrizedTypeImpl@org.crsh.auth.AuthenticationPlugin"。我认为CRaSH加载器无法正常处理。
我当然可以使用Java,但是为了坚持使用Kotlin - 如何让这个类编译成与Java版本完全相同的类型并使它由CRaSH正确加载?