Make a class use another class?

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.

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.

1 Like

You are referring to Java Generic Types
It is worth to explore this concept further and see if it fits your use case.



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).

Here is the equivalent code from openjdk 8:

1 Like

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

1 Like