java - Sort arraylist that contains subclass classes -


i have arraylist contains fruits.

i have subclass of fruits called "apples".

apples have "color" attribute other fruits subclasses don't have.

how can sort list? (i have put "apple" objects in list.)

fruits parent class, apple , others subclasses.

using instanceof 1 way of doing that.

fruits[] myfruits = ...... // array of fruits (int = 0; < myfruits.length; i++) {     if (myfruits[i] instanceof apple) {         // ...     } else {         // ...     } } 

Comments

Popular posts from this blog

How has firefox/gecko HTML+CSS rendering changed in version 38? -

javascript - Complex json ng-repeat -

jquery - Cloning of rows and columns from the old table into the new with colSpan and rowSpan -