In fact, you have 2 ways to determine the type of object.
The instanceof keyword is used first:
if (row instanceof MyRow) {
// do something
}
The second uses getClass ():
Class clazz = row.getClass();
if (clazz.equals(MyRow.class)) {}
if (MyRow.calss.isAssignableFrom(clazz)) {}
Then you can decide what you want. For example, you can even create a new instance of another class that extends Row and returns it or wraps the string passed using the argument.
source
share