Java generics - The type parameter String is hiding the type String

前端 未结 1 980
傲寒
傲寒 2020-12-10 05:48

In my interface:

public  Result query(T query)

In my 1st subclass:

public  Result query(HashMap que         


        
相关标签:
1条回答
  • 2020-12-10 06:47

    It thinks you're trying to create a type parameter -- a variable -- whose name is String. I suspect your first subclass simply doesn't import java.util.HashMap.

    In any event, if T is a type parameter of your interface -- which it probably should be -- then you shouldn't be including the <String> in the subclasses at all. It should just be

    public interface Interface<T> {
      public Result query(T query);
    }
    
    public class Subclass implements Interface<String> {
      ...
      public Result query(String queryStr) { 
        ...
      }
    }
    
    0 讨论(0)
提交回复
热议问题