开发者

References to generic type Map<K,C> should be parameterized

开发者 https://www.devze.com 2023-01-23 03:16 出处:网络
In an abstract class is the following abstract method definition: public abstract Map<String, String> aMethod(aTy开发者_如何学Cpe type);

In an abstract class is the following abstract method definition:

public abstract Map<String, String> aMethod(aTy开发者_如何学Cpe type);

I am unable to prevent this warning in Eclipse:

References to generic type Map should be parameterized

I've been searching around and can't seem to work this out. I've found others experiencing the same error, but in their cases it seemed to make sense. In mine I can't see the logic.

I could suppress warnings, but I'd like to understand what's going wrong before implementing a workaround.

Thanks.


Your Map is already parameterized, so the warning does not make sense. Try cleaning your project.


This warning is propably caused by something like

public Map aMethod(aType type);

The difference to this:

public Map<String, String> aMethod(aType type);

is that the latter creates a Map that you can only put Strings inside, but you can be sure that you always get Strings when requesting a value. The former makes you able to put everything inside it, but you can't be sure what you will get when fetching a value off the Map.


Are you sure the error is up to date with the file?

This compiles without a warning:

import java.util.Map;
class aType {}

public abstract class Main {
    public abstract Map<String, String> aMethod(aType type);
}

This however produces the error you describe:

import java.util.Map;
class aType {}

public abstract class Main {
    public abstract Map aMethod(aType type);
}
0

精彩评论

暂无评论...
验证码 换一张
取 消