I am having trouble understanding why I am getting a compilation error here. Let me share some simple code. The following code block works fine:
public class Test { public static void main(String[] args) { String[] arr = new String[0]; MethodA(arr); } public static <E> void MethodA(E[] array) { Integer[] intArray = new Integer[0]; MethodB(array, intArray); } public static <E> void MethodB(E[] array, E[] secondArray) {
The problem occurs when I add a new generic List parameter to MethodB by calling it from MethodA:
public class Test { public static void main(String[] args) { String[] arr = new String[0]; MethodA(arr); } public static <E> void MethodA(E[] array) { Integer[] intArray = new Integer[0]; List<E> someList = new ArrayList<E>(); MethodB(array, intArray, someList); } public static <E> void MethodB(E[] array, E[] secondArray, List<E> list) {
Which gives me the following error:
Exception in the "main" thread java.lang.Error: Unresolved compilation problem: MethodB method (E [], E [], List) in type Test is not applicable for arguments (E [], Integer [], List)
It seems to me that I need to change the parameter from E [] to Integer [], which is strange because he did not complain about such a thing until he presented the List parameter. Again, I feel that I must be making a stupid mistake, but I can't figure it out. Any help would be appreciated! Thanks!
source share