# Make a class use another class?

**URL:** <https://discourse.processing.org/t/make-a-class-use-another-class/23110>\
**Category:** Development\
**Created:** [August 7, 2020, 5:12pm UTC](https://discourse.processing.org/t/make-a-class-use-another-class/23110 "2020-08-07T17:12:23Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![NumericPrime](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/numericprime/32/16318_2.png) [@NumericPrime](https://discourse.processing.org/u/NumericPrime)\
**Post date:** [August 7, 2020, 5:12pm UTC](https://discourse.processing.org/t/make-a-class-use-another-class/23110/1 "2020-08-07T17:12:23Z")

</div>

Hi I’m working on a math library and I got the Idea to make a Matrix where you can put anything in. The class you put in should have certain methods. I thougt about demanding it to extend a abstract Class Number I heard you could try something like.

```auto
class Matrix<Number>{
//Do stuff
}

```

I could of course try to make a interface and get the Methods there but the first option would be better.

---

<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:** [August 8, 2020, 5:50pm UTC](https://discourse.processing.org/t/make-a-class-use-another-class/23110/2 "2020-08-08T17:50:25Z")

</div>

You are referring to Java [Generic Types](https://docs.oracle.com/javase/tutorial/java/generics/types.html)  
It is worth to explore this concept further and see if it fits your use case.

Kf

---

<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:** [August 9, 2020, 9:43pm UTC](https://discourse.processing.org/t/make-a-class-use-another-class/23110/3 "2020-08-09T21:43:33Z")

</div>

In Processing documentation and examples, the most common place that generic types are used is with ArrayList, which is a Java built-in implemented with generics that works in exactly this way (`ArrayList<Particle>`, `ArrayList<PVector>`, `ArrayList<PImage>`, et cetera).

[https://processing.org/reference/ArrayList.html](https://processing.org/reference/ArrayList.html)

Here is the equivalent code from openjdk 8:

[https://hg.openjdk.java.net/jdk8/jdk8/jdk/file/tip/src/share/classes/java/util/ArrayList.java](https://hg.openjdk.java.net/jdk8/jdk8/jdk/file/tip/src/share/classes/java/util/ArrayList.java)

---

<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 10, 2020, 3:41am UTC](https://discourse.processing.org/t/make-a-class-use-another-class/23110/4 "2020-08-10T03:41:51Z")

</div>

I’ve got this example of a class named ArrayQueue which is implemented using : 😉  
`public class ArrayQueue<E> implements Queue<E>, Cloneable, Serializable {`

> [@LinkedList vs ArrayList](https://discourse.processing.org/t/linkedlist-vs-arraylist/19946/18):
>
> It works for me for some reason. thinking In order to test ArrayQueue, I’ve picked 2 old sketches using container ArrayDeque as a Queue: pick[Docs.Oracle.com/en/java/javase/11/docs/api/java.base/java/util/ArrayDeque.html](http://Docs.Oracle.com/en/java/javase/11/docs/api/java.base/java/util/ArrayDeque.html) And then replaced that w/ my own ArrayQueue, and both sketches were still perfectly OK:ok_hand

> <https://gist.github.com/GoToLoop/145418d1dfb062c7c41a630bce5b8374>
>
> There are more than three files. show original
