我有一个实例化
Fragment
并获取类的子对象作为参数的方法。然后,在这种方法中,我想使用 Bundle
将此对象放入 putParcelable()
中,但 Android Studio 不允许我这样做,因为以下错误:
Required type: Parcelable
Provided: Class <capture of ? extends Deportista>
我的方法是:
public static PerfilFragment newInstance(String tipoDeportista,
Class<? extends Deportista> deportista) {
PerfilFragment fragment = new PerfilFragment();
Bundle args = new Bundle();
args.putString("abiertoComo", tipoDeportista);
args.putParcelable("deportista", deportista);
fragment.setArguments(args);
return fragment;
}
调用
newInstance()
时我不知道Deportista
的哪个孩子会被发送,我在方法定义中使用了Class<? extends Deportista>
,但是putParcelable()
不让我使用这个变量。怎样才能达到我所需要的?
提前谢谢大家!