Sunday 15 May 2011

java - Sort a Superclass list of objects from two Subclasses -


I have a list from Superclass A and there are two objects in that list subclasses, subclass B and subclass C and alphabetically, and then want to filter the object from subclass, something like this:

  list & lt; A & gt; List A = New Arrestist & lt; A & gt; (); Collections.sort (lista); (An Iterator: List A) if (Iterator Installation B) system. Out.printline (itater);   

My question is how should I structured my code? Am I getting the comparative & lt; A & gt; and

  should apply to public int (AA) {return name.compareTo (a.getName ()); }   

is both in superclass and subclass ? If I have not been clear enough, please say so.

EDIT: Because of such a method, I was getting an error, which I had left in one of the subclasses which had already been inherited from Superclass, and I thought the error In Comparable & lt; A & gt; There was nothing with the structure of , because I was not sure that it was right, but I already had the code as you all told me, but thanks anyway.

If you can compare the examples of SuperclassA even if they are < Code> Subclass B or subclass C , with your solution comparative In the superclass alone, the correct understanding is required if the knowledge of specific data is required for sub-classes for implementation, then add abstraction methods that supply this data to SuperclassA , And call them in your comparator.

No comments:

Post a Comment