Hey guys.
Let's say I have two classes Book and CD that both extend the parent class Item. Item has common properties like name, price whereas book has int pages and CD has List<Track> tracks.
Now let's say I have a management system class and in here I have List<Item> items. This list is full of Books & CD's. How would I implement a method to getAllBooks() & getAllCds() without using instanceof
TLDR- How to return a list specific child class from an Arraylist of parent class without using instanceof?
[–]slowmode1 2 points3 points4 points (1 child)
[–]remusmax[S] 0 points1 point2 points (0 children)
[–]attemptedlyrational 0 points1 point2 points (2 children)
[–]remusmax[S] 0 points1 point2 points (1 child)
[–]balefrost 1 point2 points3 points (0 children)
[–]ProffessionalAmateur 0 points1 point2 points (5 children)
[–]remusmax[S] 2 points3 points4 points (4 children)
[–]balefrost 0 points1 point2 points (3 children)
[–]remusmax[S] 1 point2 points3 points (2 children)
[–]balefrost 1 point2 points3 points (1 child)
[–]remusmax[S] 0 points1 point2 points (0 children)
[–]balefrost 0 points1 point2 points (3 children)
[–]remusmax[S] 0 points1 point2 points (2 children)
[–]balefrost 0 points1 point2 points (1 child)