1、泛型类的静态上下文中类型变量失效。
//静态域或者方法里不能引用类型变量
private static T instance;
//静态方法 本身是泛型方法就行
private static <T> T getInstance(){
}2、不能实例化类型变量。
// public Restrict() {
// this.data = new T();
// }3、不能用基本类型实例化泛型参数。
// NormalGeneric<double> normalGeneric = new NormalGeneric<>();
NormalGeneric<Double> normalGeneric = new NormalGeneric<>();4、不能创建参数化类型的数组。
Restrict<Double>[] restrictArray; Restrict<Double>[] restricts = new Restrict<Double>[10];
以上就是Java泛型的限制是什么?的详细内容,更多请关注php中文网其它相关文章!
java怎么学习?java怎么入门?java在哪学?java怎么学才快?不用担心,这里为大家提供了java速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号