# Object is not working in new versions of Processing

**URL:** <https://discourse.processing.org/t/object-is-not-working-in-new-versions-of-processing/16686>\
**Category:** Beginners\
**Created:** [December 28, 2019, 8:42pm UTC](https://discourse.processing.org/t/object-is-not-working-in-new-versions-of-processing/16686 "2019-12-28T20:42:24Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![GeorgeJava](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/georgejava/32/7646_2.png) [@GeorgeJava](https://discourse.processing.org/u/GeorgeJava)\
**Post date:** [December 28, 2019, 8:42pm UTC](https://discourse.processing.org/t/object-is-not-working-in-new-versions-of-processing/16686/1 "2019-12-28T20:42:24Z")

</div>

Hello, i want to store some type of Var in the Object, and it cant…  
see

```auto
Object[] vars = new Object[] { 5, 10.0, true, 20 };
println(vars[0]);

```

Tell me why ? Or how to make it working… ? ☹

---

<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:** [December 28, 2019, 8:47pm UTC](https://discourse.processing.org/t/object-is-not-working-in-new-versions-of-processing/16686/2 "2019-12-28T20:47:28Z")

</div>

It’s definitely working for me w/ 64-bit PDE 3.5.3 under Win 8.1: 🤖

```auto
Object[] vars = { 5, 10.0, true, 20 };
println(vars[0]); // 5
println(vars); // 5 10.0 true 20
exit();

```

---

<div class="post-metadata">

**Author:** ![GeorgeJava](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/georgejava/32/7646_2.png) [@GeorgeJava](https://discourse.processing.org/u/GeorgeJava)\
**Post date:** [December 28, 2019, 8:51pm UTC](https://discourse.processing.org/t/object-is-not-working-in-new-versions-of-processing/16686/3 "2019-12-28T20:51:02Z")

</div>

WTF, maybe editor gets stuck and tells me bullsh1ts, i open up another new window and it working 😛

---

<div class="post-metadata">

**Author:** ![GeorgeJava](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/georgejava/32/7646_2.png) [@GeorgeJava](https://discourse.processing.org/u/GeorgeJava)\
**Post date:** [December 28, 2019, 8:56pm UTC](https://discourse.processing.org/t/object-is-not-working-in-new-versions-of-processing/16686/4 "2019-12-28T20:56:48Z")

</div>

How to get Class from objects, thanks \<3 🙂

```auto
Object[] vars = { 5.5, 10.0, true, 20 };
  Class[] types = new Class[vars.length];

  for (int i = 0; i < vars.length; i++)
    types[i] = vars[i].getClass();

  for (int i = 0; i < vars.length; i++)
    println(types[i].getSimpleName(), vars[i]);

  exit();

```

---

<div class="post-metadata">

**Author:** ![kfrajer](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kfrajer/32/196_2.png) [@kfrajer](https://discourse.processing.org/u/kfrajer)\
**Post date:** [December 28, 2019, 9:02pm UTC](https://discourse.processing.org/t/object-is-not-working-in-new-versions-of-processing/16686/5 "2019-12-28T21:02:26Z")

</div>

The output from the code above is:

```auto
Float 5.5
Float 10.0
Boolean true
Integer 20

```

So it is printing the Class of each object. S this not working for you? What is your question?  
Also, create a new post for new questions instead of adding questions to this posts.

Kf

---

<div class="post-metadata">

**Author:** ![GeorgeJava](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/georgejava/32/7646_2.png) [@GeorgeJava](https://discourse.processing.org/u/GeorgeJava)\
**Post date:** [December 28, 2019, 9:05pm UTC](https://discourse.processing.org/t/object-is-not-working-in-new-versions-of-processing/16686/6 "2019-12-28T21:05:07Z")

</div>

BTW, can i append some object to Objects array ?

i try this, but not working

`vars = append(vars, new Object[]{22});`

---

<div class="post-metadata">

**Author:** ![kfrajer](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kfrajer/32/196_2.png) [@kfrajer](https://discourse.processing.org/u/kfrajer)\
**Post date:** [December 28, 2019, 9:16pm UTC](https://discourse.processing.org/t/object-is-not-working-in-new-versions-of-processing/16686/7 "2019-12-28T21:16:02Z")

</div>

`vars = (Object[])append(vars, 22);`

Ensure you are checking the reference as this is documented there: [append() / Reference / Processing.org](https://processing.org/reference/append_.html), quoting:

> When using an array of objects, the data returned from the function must be cast to the object array’s data type. For example: _SomeClass[] items = (SomeClass[]) append(originalArray, element)_

Kf

---

<div class="post-metadata">

**Author:** ![GeorgeJava](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/georgejava/32/7646_2.png) [@GeorgeJava](https://discourse.processing.org/u/GeorgeJava)\
**Post date:** [December 28, 2019, 9:23pm UTC](https://discourse.processing.org/t/object-is-not-working-in-new-versions-of-processing/16686/8 "2019-12-28T21:23:26Z")

</div>

Thank you !

```auto
void setup() {
  Prescription test = new Prescription();

  test.add("Hello world");
  test.add(123.456);
  test.add(true);
  test.add(5689);
  test.add((byte)63);

  test.out();

  // In the console you can see this list of values that we stored in a Prescription

  // String Hello world
  // Float 123.456
  // Boolean true
  // Integer 5689
  // Byte 63

  exit();
}

class Prescription {

  Object[] vars;
  Class[] types;

  Prescription() {
    vars = new Object[0];
  }

  void add(Object obj) {
    vars = (Object[])append(vars, obj);
  }

  void getClasses() {
    types = new Class[vars.length];
    for (int i = 0; i < vars.length; i++)
      types[i] = vars[i].getClass();
  }

  void out() {
    getClasses();

    for (int i = 0; i < vars.length; i++)
      println(types[i].getSimpleName(), vars[i]);
  }
}

```
