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)
精彩评论