Diry Override?

I believe I have seen the syntax for a ditry override in java before...somthing like...CustomButton = new CustomButton( x,y ){onClick(){System.out.println( "custom function for this instance only!" );}}am I insane?
[284 byte] By [Kullgena] at [2007-10-1 1:20:25]
# 1
What is a dirty override?This is not valid java so it is hard to see what point you are trying to illustrate.
Peter-Lawreya at 2007-7-8 1:38:13 > top of Java-index,Administration Tools,Sun Connection...
# 2
perhaps you wish me to ask the question more academically?Does java have the ability to to override a speific method of an instnace without having to explicitly extend the class?AKA, Dirty Override!
Kullgena at 2007-7-8 1:38:13 > top of Java-index,Administration Tools,Sun Connection...
# 3
Yes, they are called anonymous iner classes. http://java.sun.com/docs/books/tutorial/java/javaOO/innerclasses.html
jsalonena at 2007-7-8 1:38:13 > top of Java-index,Administration Tools,Sun Connection...
# 4

Ummm..... Anonymous classes are classes that have no specified name. The only time I use them is when I need to impliment an interface where the definition is rather short. This does not actually override any methods. You might be able to do that by extending a class (I don't know if you can), but then you're extending the class, defeating the point of discussing it.

To my knowledge, there is no way to override a method without extending a class. There are classes that act only as they are told to by certain interfaces. For exmaple, a JButton will normally only react to a click by calling ActionListener.actionPerformed on the ActionListeners added to it. You might think of this as an override, but it really isn't. It's closer to altering the JButton's underlying model in the preferred manner. Those interfaces can be implemented by anonymous classes, but you're not performing a "dirty override."

The only even semi-dirty way to work with Java that I know of is through the reflection package, but that's really just a work around sort of thing, not entirely dirty, and you can't use it to override methods.

Legend_Keepera at 2007-7-8 1:38:13 > top of Java-index,Administration Tools,Sun Connection...
# 5
> Does java have the ability to to override a speific method of an instnace without having to explicitly extend the class?No, every object must be an instance of a class. You can write "Dirty Override" like code with anonymous classes but this is not a true dirty override.
Peter-Lawreya at 2007-7-8 1:38:13 > top of Java-index,Administration Tools,Sun Connection...