开发者

Generic Method Compile Error with Class<T>

I have a method with the following 开发者_运维百科signiture:

public <T> T encode(String[] data, Class<T> type)

Whenever I invoke it, I get a compile error such as:

The method encode(String[], Class<T>) is not applicable for the arguments (String, Class<Integer>)"

In this case when I pass it Integer.class. (It gives a similar errors for any Object.class)

From what I have seen with generic methods, this should work and use Integer as T. What am I doing wrong?


Your error message says it all; you are trying to pass in a String and your method expects a String array.

The method encode(String[], Class) is not applicable for the arguments (String, Class)

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜