public class TableModel2 extends TableModel1 { ... }

TableModel2 tableModel = new TableModel2();

boolean t1 = tableModel instanceof TableModel1;
boolean t2 = tableModel instanceof TableModel2;

在上面的示例中,t1t2true。那么,如何使用TableModel1区分TableModel2instanceof呢?

最佳答案

boolean t2 = tableModel.getClass().equals(TableModel1.class); //False
boolean t2 = tableModel.getClass().equals(TableModel2.class); //True

09-26 12:06