A couple of days ago, I saw an interesting way to prohibit the use of a method from a superclass. A coworker of mine wrote a subclass of a JTextField that should display a date in a specific fashion. Before you comment the obvious: Yes, there where reasons not to use JFormattedTextField. ;)
Here's how he wrote the new class:
public void setDate
(Date date
) { c.setTime(date);
// the real method was a bit more complicated, but for the example that is sufficient
}
/**
* @deprecated Use setDate(Date date) instead
*/
@Deprecated
@Override
public void setText
(String arg0
) { "This method is not supported. Use setDate(Date date) instead.");
}
}