在Java中使用param Class <t>的方法可以,但在kotlin中则不行

时间:2019-04-28 02:20:46

标签: generics kotlin

在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

0 个答案:

没有答案