gpt4 book ai didi

java - 为什么泛型类型只适用于对象?

转载 作者:行者123 更新时间:2023-12-02 00:47:30 26 4
gpt4 key购买 nike

我的意思是

interface A <T> {
}

class AImpl implements A < Integer > { // why not A< int >
}

我读过这篇文章article并用谷歌搜索它,但我仍然不知道为什么它只适用于对象而不适用于原始数据类型(int,void)?

最佳答案

这不仅仅是通配符 - Java 泛型根本不支持原始类型作为类型参数。

请参阅Java Generics FAQ有关 Java 泛型的更多信息,以及 this question in particular .

关于java - 为什么泛型类型只适用于对象?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4538002/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com