Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Collections sort statement not being accepted

 
Armando Moncada
Ranch Hand
Posts: 30
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The Eclipse editor won't accept the line where I am trying to sort the array list using my custom comparator. (It is the second to the list line of code). Eclipse says
The method sort(List<T>, Comparator<? super T>) in the type Collections is not applicable for the arguments (ArrayList<String>, SortNames.CelebrityNamesFile.CompareLastName).

The purpose of the program is to read names from a text file, add them to an array list, sort the array list in natural order, then print it, sort the arraylist by last name, then print it again.

I have read the pertinent chapters in Just Java, Ivor Horton's Beginning Java 7, Head First Java, Googled, StartPaged, and Binged the internet for examples but I still don't know what it wants.
 
Henry Wong
author
Marshal
Pie
Posts: 20997
76
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First take the error ...

The method sort(List<T>, Comparator<? super T>) in the type Collections is not applicable for the arguments (ArrayList<String>, SortNames.CelebrityNamesFile.CompareLastName).


then try to prove the compiler wrong, by finding a type for T that will work.

Henry
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic