gpt4 book ai didi

Java泛型类型转换

转载 作者:塔克拉玛干 更新时间:2023-11-01 22:48:44 24 4
gpt4 key购买 nike

示例代码如下:

public static BaseListAdapter<? extends Item> getListAdapter() {
...
}

...

public class MyClass<T extends Item> {
...
BaseListAdapter<T> adapter = (BaseListAdapter<T>) getListAdapter();
...
}

编译器提示存在未经检查的转换。

java: unchecked cast
need: BaseListAdapter<T>
found: BaseListAdapter<capture#1, ? extends Item>

我想知道为什么会产生这个警告,以及如何解决。

最佳答案

你可能想要

public static <T extends Item> BaseListAdapter<T> getListAdapter() {

关于Java泛型类型转换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17651548/

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