Question about the AbstractTableModel class and JTable

From: Edward H. Fabrega (spiritualfields_at_wavecable.com)
Date: 09/29/04


Date: Tue, 28 Sep 2004 23:44:53 -0700

AbstractTableModel is an abstract class. From the SRC code that comes with
JDK1.5.0-RC:

public abstract class AbstractTableModel implements TableModel, Serializable
{
//
// Instance Variables
//

    /** List of listeners */
    protected EventListenerList list

(snip)**************************************************

In the JTable class, one of the constructors goes like this:

    public JTable(final Object[][] rowData, final Object[] columnNames) {
        this(new AbstractTableModel() {
            public String getColumnName(int column) { return
columnNames[column].toString(); }
            public int getRowCount() { return rowData.length; }
            public int getColumnCount() { return columnNames.length; }
            public Object getValueAt(int row, int col) { return
rowData[row][col]; }
            public boolean isCellEditable(int row, int column) { return
true; }
            public void setValueAt(Object value, int row, int col) {
                rowData[row][col] = value;
                fireTableCellUpdated(row, col);
            }
        });
    }

My question is concerning the creation of an instance of AbstractTableModel
in the JTable constructor with new. Isn't this illegal, and shouldn't it
generate a compile error because AbstractTableModel is an abstract class? I
was under the impression that attempting such a thing would cause a compile
error. Obviously I must be mistaken and am in need of some clarification.



Relevant Pages