Getting enum inside a class constructor

Hello,
I ran into this problem while working on simple object check box / onoff button.
I wanted to be able to determin the type(looks) of my button in the costructor by an enum
for example: checkbox_box, checkbox_circle, switch and so on.
I am aware of the possibility of using a String or workaround using a valueOf()
Sadly both includes the use of String in the costructor and that just what i am trying to avoid.

Here’s a link to a post i found that seems to be working in Java only:

Any suggestions on how to make it possible in Processing?
Here’s a simle pseudo code of what i am trying to achieve:

Test myTest;
myTest = new Test(Type.E1);


class Test {
  Test(enum Type) {
    this.Type = t;
  }
  void run() {
    switch(t) {
    case E1:
      println("1");
      break;
    case E2:
      println("2");
      break;
    default:
    }
  }
}

public enum Type {
  E1, E2
}

Why not just an actual runnable code? :man_shrugging:

Test myTest = new Test(Type.E1);

void setup() {
  println(myTest);
  myTest.run();

  myTest.t = Type.E2;

  println(myTest);
  myTest.run();

  exit();
}

enum Type {
  E1, E2
}

class Test {
  Type t;

  Test(final Type tt) {
    t = tt;
  }

  void run() {
    switch(t) {
    case E1:
      println("1");
      break;
    case E2:
      println("2");
      break;
    }
  }

  @Override String toString() {
    return t.toString();
  }
}
2 Likes