I have an API that processes a set of objects all extending a particular class which does not have an income field
class Person { ... }
Say I want to make a call getting incomes. Not all of the subclasses here have an income field
class Child { ... }
class FullTimeEmployedPerson { ... }
class TrustFundKid { ... }
This process would call a #getIncome() method on either of the latter two. Now, my API is guaranteed never to get a Child passed to it so I want to skip the pleasantries and simply have something like
String getParsedIncome(Person person) {
return FooBar.parse(person.getIncome());
}
What is a realistic approach for this?