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 › no interface in the first line
Page Index Toggle Pages: 1
no interface in the first line (Read 506 times)
no interface in the first line
Apr 10th, 2010, 2:22am
 
I am posting this here because I cannot login to the bug tracker; is the script synchronizing discourse and bugzilla account database still working after the "big spam" shutdown?


Anyway,

Severity: Low

The following code fails to compile:

interface MyInterface {}

while this works:

class MyClass {}
interface MyInterface {}

just adding a class declaration, variable declaration, function declaration, or anything but whitespace makes it works.

Reproducible: Always
Re: no interface in the first line
Reply #1 - Apr 10th, 2010, 3:03am
 
In general, when you declare interfaces, classes or even simple functions, you must include setup().
Code:
interface MyInterface {}
void setup() { size(200, 200); }
works.
That's because if setup() isn't present, one is automatically generated, and all code goes inside. New classes inside a function are OK, actually, but you can't define a function or an interface inside a function!
Actually, in the cases that works (defining something before the interface definition), the interface is quietly removed from the code. If you write:
Code:
class MyClass implements MyInterface { int x = 5; }
interface MyInterface { public static final W = 10; }
you will get an error: Cannot find a class or type named "MyInterface".
Page Index Toggle Pages: 1