I've got a class called Field and it's got several subclasses such as TextField and LabelField.
I'm working with a method that returns the Field that currently has focus:
Field field = screen.getFieldWithFocus();
I don't know the type it will return, so I do something like this:
if(field instanceof TextField){ TextField tf = (TextField)field }
if(field instanceof LabelField){ LabelField lf = (LabelField)field }
// etc
This works, but I'm curious if there is another way of determining what the subclass is without using instanceof? Perhaps reflection?
I want it to autocast for me where I call getFieldWithFocus()
Thanks,
Drew