# 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:** 1

<div class="post-metadata">

**Author:** ![no\_spaces](https://avatars.discourse-cdn.com/v4/letter/n/f04885/32.png) [@no\_spaces](https://discourse.processing.org/u/no_spaces)\
**Post date:** [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/1 "2020-08-02T13:02:31Z")

</div>

So I want to do something like this, where you add a new instance of a class determined by a variable (trust me, I have a good reason for this, but I can’t tell…)

```auto
Class type;
dummy1 list[] = new dummy1[3];

void setup() {
  type = dummy2.class;
  list[0] = new type;
  type = dummy3.class;
  list[1] = new type;
}

class dummy1 {}

class dummy2 extends dummy1 {}

class dummy3 extends dummy1 {}

```

This (obviously) doesn’t work… I am wondering if there is a different correct way to do this. Apologies if the answer is easy and I am just 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)._
