public class TableModel2 extends TableModel1 { ... }
TableModel2 tableModel = new TableModel2();
boolean t1 = tableModel instanceof TableModel1;
boolean t2 = tableModel instanceof TableModel2;
在上面的示例中,
t1
和t2
是true
。那么,如何使用TableModel1
区分TableModel2
和instanceof
呢? 最佳答案
boolean t2 = tableModel.getClass().equals(TableModel1.class); //False
boolean t2 = tableModel.getClass().equals(TableModel2.class); //True