# Getting enum inside a class constructor

**URL:** <https://discourse.processing.org/t/getting-enum-inside-a-class-constructor/38722>\
**Category:** Coding Questions\
**Created:** [September 12, 2022, 10:23am UTC](https://discourse.processing.org/t/getting-enum-inside-a-class-constructor/38722 "2022-09-12T10:23:11Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![iudividnal](https://avatars.discourse-cdn.com/v4/letter/i/22d042/32.png) [@iudividnal](https://discourse.processing.org/u/iudividnal)\
**Post date:** [September 12, 2022, 10:23am UTC](https://discourse.processing.org/t/getting-enum-inside-a-class-constructor/38722/1 "2022-09-12T10:23:11Z")

</div>

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:

> <https://stackoverflow.com/questions/20069410/how-to-pass-an-enum-value-to-a-constructor>

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

```auto
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
}

```

---

<div class="post-metadata">

**Author:** ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)\
**Post date:** [September 12, 2022, 11:13am UTC](https://discourse.processing.org/t/getting-enum-inside-a-class-constructor/38722/2 "2022-09-12T11:13:01Z")

</div>

> [@iudividnal](#):
>
> Here’s a simple pseudo code…

Why not just an actual runnable code? 🤷‍♂️

```auto
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();
  }
}

```
