I have a BatchProcessing code using ‘PriorityQueue’ in a Reader class defined as follows:
Queue<List<Profile>> profileQueue = new PriorityQueue<>();
List<Profile> profiles = dao.getProfiles() // this step is getting data returned from database call
profileQueue.add(profiles);
When the above add call is executed I get the following error:
java.lang.ClassCastException: class java.util.ArrayList cannot be cast to class java.lang.Comparable (java.util.ArrayList and java.lang.Comparable are in module java.base of loader ‘bootstrap’)
I tried implementing Comparable<Profile> into my Profile class and override the compareTo method but that didn’t help as I think because it is not an ArrayList<Profile>.
I also tried using addAll but that doesn’t help as it is not a part of Collection.
Also, creating another PriorityQueue and adding each ‘Profile’ object to the queue doesn’t work either.