Java泛型不兼容类型 [英] Java generics incompatible type

查看:143
本文介绍了Java泛型不兼容类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个方法(使用泛型):

  public class ExtA< T> Ex< T>扩展ArrayList 
{
public< T> EXTA< T>实施例< T> filt(函数< T,Boolean> a ...)
{
//代码
}
}

给了我一个不兼容的类型错误。 解除方案

从您的 filt 方法声明中引导< T> 。它隐藏了应用于该类的通用 T 类型。


I have this method (using generics) :

public class ExtA<T>Ex<T> extends ArrayList
{    
    public<T> ExtA<T>Ex<T> filt(Function<T, Boolean> a...)
    {
  //code
    }
}

giving me an "incompatible types error".

解决方案

Remove the leading <T> from your filt method declaration. It's shadowing the generic T type applied to the class.

这篇关于Java泛型不兼容类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆