# Concat with an object not working

**URL:** <https://discourse.processing.org/t/concat-with-an-object-not-working/20632>\
**Category:** Beginners\
**Created:** [May 8, 2020, 4:18pm UTC](https://discourse.processing.org/t/concat-with-an-object-not-working/20632 "2020-05-08T16:18:03Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Eyetoof](https://avatars.discourse-cdn.com/v4/letter/e/f05b48/32.png) [@Eyetoof](https://discourse.processing.org/u/Eyetoof)\
**Post date:** [May 8, 2020, 4:18pm UTC](https://discourse.processing.org/t/concat-with-an-object-not-working/20632/1 "2020-05-08T16:18:03Z")

</div>

I’ve stripped the issue I am having down to isolate the issue. I figure its just a data type issue and I should maybe switch to ArrayLists but… I wanted to see if anyone had a specific insight.

First off here is what I am trying to do, and it works fine with color(); vars.

![color_works](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/4/42036c0cf85fc0987db963f11edd36dc6abb808b.jpeg)

here is shot of the class define and the main tab where concat is not happy.

 ![HSB_ValFail](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/8/85a5418c73cedc2b10baf06eb79b4a4d59fafe8f.jpeg)

I just checked the documentation and Object is listed as a valid type to use concat with…

thanks in advance for any help.

---

<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:** [May 8, 2020, 4:32pm UTC](https://discourse.processing.org/t/concat-with-an-object-not-working/20632/2 "2020-05-08T16:32:52Z")

</div>

> [@Eyetoof](#):
>
> … where **concat()** is not happy.

> **[concat() / Reference](https://processing.org/reference/concat_.html)**
>
> Concatenates two arrays. For example, concatenating the array { 1, 2, 3 } and the array { 4, 5, 6 } yields { 1, 2, 3, 4, 5, 6 }. Both parameters must be arrays of the same datatype. When u…

> 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[]) concat(array1, array2);`.

If you dislike using the `(cast)` operator for **concat()** I can write for you a version that doesn’t need it like I did for [**append()**](https://processing.org/reference/append_.html):

> [@Unable to append to an array of G4P objects](https://discourse.processing.org/t/unable-to-append-to-an-array-of-g4p-objects/19898/7):
>
> Using (cast) is indeed not ideal. If you wish, you can override append() pasting the 3 methods below on your sketch, so (cast) isn’t needed anymore: wink static final \<T\> T[] expand(final T[] list) { return expand(list, list.length \<\< 1); } static final \<T\> T[] expand(final T[] list, final int newSize) { return java.util.Arrays.copyOf(list, newSize); } static final \<T\> T[] append(final T[] list, final T value) { final T[] arr = expand(list, list.length + 1); arr[arr.length - 1] = va…

---

<div class="post-metadata">

**Author:** ![jeremydouglass](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jeremydouglass/32/20_2.png) [@jeremydouglass](https://discourse.processing.org/u/jeremydouglass)\
**Post date:** [May 8, 2020, 4:50pm UTC](https://discourse.processing.org/t/concat-with-an-object-not-working/20632/3 "2020-05-08T16:50:54Z")

</div>

Thanks for sharing this question!

When possible, please paste code as text rather then as screenshots. Error messages and warnings can also be cut-pasted by clicking on the error bar.

---

<div class="post-metadata">

**Author:** ![Eyetoof](https://avatars.discourse-cdn.com/v4/letter/e/f05b48/32.png) [@Eyetoof](https://discourse.processing.org/u/Eyetoof)\
**Post date:** [May 11, 2020, 10:57pm UTC](https://discourse.processing.org/t/concat-with-an-object-not-working/20632/4 "2020-05-11T22:57:17Z")

</div>

Jeremy, Ah yes I understand, sorry about that.

---

<div class="post-metadata">

**Author:** ![Eyetoof](https://avatars.discourse-cdn.com/v4/letter/e/f05b48/32.png) [@Eyetoof](https://discourse.processing.org/u/Eyetoof)\
**Post date:** [May 11, 2020, 10:58pm UTC](https://discourse.processing.org/t/concat-with-an-object-not-working/20632/5 "2020-05-11T22:58:02Z")

</div>

Thank you GoTo, I did go the casting route and its working great.

Cheers!

Toof
