We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › Anonymous classes
Page Index Toggle Pages: 1
Anonymous classes (Read 566 times)
Anonymous classes
Sep 4th, 2006, 6:59am
 
Java usually lets you do something like this:
Code:
Foo f = new Foo() {
public int method(int input) {
return input + 5;
}
};


Which will extend a previously defined class named Foo, adding or overriding the methods that are defined in the declaration. Processing seems to choke on this. Is this a bug or a feature? (I understand it's a bit confusing for beginners to understand what's going on with that syntax. Perhaps enable it in full-on Java programming mode?)
Re: Anonymous classes
Reply #1 - Sep 4th, 2006, 4:00pm
 
have you tried it in regular java mode? also, try placing this after the majority of the class definition--if it comes first in the sketch, that may be what's confusing the preprocessor.
Re: Anonymous classes
Reply #2 - Sep 5th, 2006, 8:13pm
 
Sorry, my bad. Java apparently only lets you override methods defined in the class that is being implicitly extended; it doesn't let you add new methods. Works fine in both normal mode and regular Java mode.
Page Index Toggle Pages: 1