I am trying to call a method from another class with list but it is not letting me. Here is my call statement:
case 2: pm.displayList(list);
break;
case 3: pm.searchList(scan, list);
break;
And here are my methods:
public void displayList(List list){
System.out.print(list);
}
//search for element
public void searchList(Scanner scan, List list){
System.out.println("Search for element:\t");
String p = scan.nextLine();
if (list.contains(p))
System.out.println(p + " is in the list");
else
System.out.println(p + " is not in the list.");
}
Here is my error:
MyProgram7.java:50: displayList(java.util.List) in Prog7Methods cannot be applied to (MyList<java.lang.String>)
case 2: pm.displayList(list);
^
MyProgram7.java:53: searchList(java.util.Scanner,java.util.List) in Prog7Methods cannot be applied to (java.util.Scanner,MyList<java.lang.String>)
case 3: pm.searchList(scan, list);
The functions expect a
List, and you’re supplying aMyList<java.lang.String>. Check thatMyListimplements theListinterface (I bet it doesn’t).Also, you probably shouldn’t be using the raw
Listtype;List<String>— orMyList<String>, as appropriate — would be preferable.