I swear this code worked in processing 4.1.1 or maybe 4.0b7 cause that was how the tutorial worked(well the class is in a different file but processing reads it like tht so it does not matter) can someone tell me what changed, please
When we click the “Run” button, the PDE concatenates all the “.pde” files as 1 “.java” file, and they’re also wrapped up inside 1 PApplet subclass.
My “fixed” posted example would become something like this “.java” file:
// ...
public class sketch_static extends PApplet {
public void setup() {
class Ball {
}
Ball ball = new Ball();
println(ball);
exit();
noLoop();
}
static public void main(String[] passedArgs) {
// ...
}
}
So the whole “static” code, besides being wrapped up in 1 PApplet subclass, it’s also been moved inside callback method setup().
Although Java doesn’t allow us defining a method inside another method, surprisingly we can define classes inside methods!
In such case the order is important, b/c we have to define an internal class before we could instantiate it via new.