# How do you choose what class you add to a list with a variable?

**URL:** https://discourse.processing.org/t/how-do-you-choose-what-class-you-add-to-a-list-with-a-variable/22987
**Category:** Coding Questions
**Created:** [August 2, 2020, 1:02pm UTC](https://discourse.processing.org/t/how-do-you-choose-what-class-you-add-to-a-list-with-a-variable/22987 "2020-08-02T13:02:31Z")
**Posts on this page:** 1
**Showing post:** 3

<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: [August 2, 2020, 3:03pm UTC](https://discourse.processing.org/t/how-do-you-choose-what-class-you-add-to-a-list-with-a-variable/22987/3 "2020-08-02T15:03:34Z")

</div>

```auto
// https://Discourse.Processing.org/t/
// how-do-you-choose-what-class-you-add-to-a-list-with-a-variable/22987/3

// GoToLoop (2020/Aug/02)

static final int DUMB = 0, DUMMY = 1, DUMBER = 2;
int dumbType;

void draw() {
  dumbType = (int) random(3);
  final Dumb d = getDumb(dumbType);
  print(d, TAB);

  noLoop();
  background((color) random(#000000));
}

void mousePressed() {
  redraw();
}

Dumb getDumb(final int which) {
  switch (which) {
  case DUMB: 
    return new Dumb();
  case DUMMY: 
    return new Dummy();
  case DUMBER:
    return new Dumber();
  default: 
    throw new RuntimeException("Unknown Dumb Type Value!");
  }
}

class Dumb {
  @Override String toString() {
    return getClass().getSimpleName();
  }
}

class Dummy extends Dumb {
}

class Dumber extends Dumb {
}

```

---

_[View the full topic](https://discourse.processing.org/t/how-do-you-choose-what-class-you-add-to-a-list-with-a-variable/22987)._
