开发者

Generic Method Compile Error with Class<T>

开发者 https://www.devze.com 2023-03-17 05:33 出处:网络
I have a method with the following 开发者_运维百科signiture: public <T> T encode(String[] data, Class<T> type)

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

精彩评论

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