在Java中使用param类的方法是可以的,但在Kotlin中是不可行的
public interface AuthConf<T> {
}
public class AuthConfDao<T> implements AuthConf<T> {
}
public class AuthManager<T> {
public <C extends AuthConf<T>> C rmConf(Class<C> clazz) {
//...
return null;
}
}
//test in java
public void test() {
AuthManager<Integer> auth = new AuthManager<Integer>();
auth.rmConf(AuthConfDao.class);
}
//test in kotlin
fun test() {
auth.rmConf<AuthConfDao<*>>(AuthConfDao<*>::class.java)
auth.rmConf<AuthConfDao<Int>>(AuthConfDao<Int>::class.java)
auth.rmConf(AuthConfDao<Int>::class.java)
}
错误是:
Type argument is not within its bounds. Expected: AuthConf<Int!>!
Found: AuthConfDao<*> Only classes are allowed on the left hand side of a
class literal