Good day!
There is a factory for the creation of different varieties of coffee (Arabica or Robusta).
They, in turn, are inherited (that is, Arabica and Robusta classes) from the abstract class Coffee.
At the moment, the creation of objects using the factory.
Then you need to shove these objects into a collection called the Van of coffee.
Great, everything turns out, the created objects are added to the CoffeeVan collection (this is a separate class).
Now I create a class CoffeeWeightComparator (I want to sort by weight).
public class CoffeeWeightComparator implements Comparator<Coffee> { public int compare(Coffee o1, Coffee o2) { Double weight1 = o1.getWeight(); Double weight2 = o2.getWeight(); return weight1.compareTo(weight2); } } Next comes the Main method.
public class Runner { public static void main(String[] args) { CoffeeFactory arabica = CoffeeFactory.create(0); CoffeeFactory robusta = CoffeeFactory.create(1); CoffeeVan coffeeVan = new CoffeeVan(new ArrayList<CoffeeFactory>()); coffeeVan.fillVan(arabica); coffeeVan.fillVan(robusta); System.out.println(coffeeVan.toString()); Collections.sort(coffeeVan, new CoffeeWeightComparator()); } } And when I call the sort on the last line, he swears at
Wrong 1st argument type. Found: CoffeeVan, requid Coffee
I can't pass coffee, because the collection is in CoffeeVan; objects are simply created in the Coffee class.