Accessing PApplet methods in static

Hi, I’m trying to access PApplet methods in a static class, in this case the color() method. I’ve tried following this discussion, but I can’t make it work.
I’ve written this:

static class myclass {
  static int mycolor(final PApplet p) {
    int out = p.color(0);
    return out;

but it doesn’t compile due to “unexpected token: int”.

I don’t really know what I’m doing wrong, hope you can help me!

1 Like

You’re doing alright! It’s a PDE’s pre-processor bug! :bug:

B/c the name color is both a Processing’s datatype: color

And a PApplet & PGraphics method name: color()

It seems like the name color can’t be used w/ the dot . operator within a “.pde” file. :astonished:

This example calling color() as a method of a PGraphics object also triggers this bug: :gun:

final PGraphics pg = createGraphics(10, 10);
pg.color(0); // unexpected token: .

As a workaround, you can place your static classes in a “.java” file instead. :bulb:

You just need to remove the static keyword before class, b/c top classes inside “.java” files are implicitly static already. :wink:

You should also report this issue on Processing’s repo: :octopus:

1 Like

Thank you for your help and your workaround! I will do that =)

I’ve also created an issue, here is the link to it for future viewers.