1

My class extended from DefaultTableModel

I try:

super.removeRow(...);

And

this.removeRow(...);

Why do they both work?

Garrison Neely
  • 3,238
  • 3
  • 27
  • 39
Sajad
  • 2,273
  • 11
  • 49
  • 92
  • @APoliteBoy cause `Your class` is a `DefaultTableModel` – nachokk Sep 09 '13 at 20:05
  • @A Polite Boy please whats what – mKorbel Sep 09 '13 at 20:08
  • that's the way objects works, has nothing to do with `defaulttablemodel` or `swing` is `oop` – nachokk Sep 09 '13 at 20:13
  • @mKorbel What `why.........` ? – Sajad Sep 09 '13 at 20:17
  • 1
    search here for AbstractTableModel, here are a few most complex code examples, the same methods you can to override in DeafultTableModel, but then I'm miss any reason to override that because this method is accesible in whole JVM instance, and advantage of DeafultTableModel is call whatever from any corners of current JVM, then this or super inside class extends DefaultTableModel are useless chars, removeRow will be execured without this or..., the same as from JButtons Action, etc – mKorbel Sep 09 '13 at 20:23
  • @A Polite Boy here is [quite refference code for DefaultTableMode (please ignore my ego) why was there my why](http://stackoverflow.com/a/16664124/714968) – mKorbel Sep 09 '13 at 20:31

3 Answers3

5

super refers to the super (parent) type's implementation.

this refers the the current type's implementation, if one exists, otherwise looks up the inheritance tree, ie. does the same as super.

Depending on how your class extends DefaultTableModel, they might be calling the same method.

Sotirios Delimanolis
  • 274,122
  • 60
  • 696
  • 724
2

not an answer, but this.whatever can be pretty misspeled in most complex Swing GUI

super.removeRow(...);

And

this.removeRow(...);

should be (my view to avoid ....)

myTableModel.removeRow() - e.g. ((DefaultTableModel) table.getModel()).removeRow(row);

or you override in XxxTableModel

public void removeRowAt(int row) {

mKorbel
  • 109,525
  • 20
  • 134
  • 319
1

Actually they are calling same method i.e. removeRow in parent class for your case.

Only for the case when you decide to override removeRow in your child class then you can make a call to super.removeRow() like this:

@Override
void removeRow() {
   // call parent class's removeRow
   super.removeRow()
   // rest of implementation
}
anubhava
  • 761,203
  • 64
  • 569
  • 643