I have a base class: "Working Items". Witch is extended by 3 subclasses: "Bug", "Story", "Feedback". I receive a command from the console (String), to list all types of Working Items, or one specific type (Bug, Story, Feedback). I have a collection of type WorkingItems, which contains all of the 3 above mention subclasses. How can I validate while looping the collection if the current object is Bug, Story or Feedback (I can't use instanceof)?
I don't want to divide the collection of Working Items into 3 smaller collections of Bugs, Stories, Feedbacks.
private String listAllWorkingItems(StringBuilder result) {
WIMRepository.getWorkItemList().forEach(workItem -> result.append(workItem.toString()));
return result.toString();
}
private String listAllStories(StringBuilder result) {
WIMRepository.getWorkItemList(); //TODO
return result.toString();
}
private String listAllBugs(StringBuilder result) {
WIMRepository.getWorkItemList() //TODO
return result.toString();
}
private String listAllFeedbacks(StringBuilder result) {
WIMRepository.getWorkItemList() //TODO
return result.toString();
}
The result should be like this:
Command: show all Result: "printing working items collection"
Command: show bugs Result: "printing only the bugs from working items collection"