Java abstract Number operator +=

I would like to create an abstract Vector3 class. So what I did was:

class Vector3<T extends Number> {}

And I have the 3 components:

T x, y, z;

However this way I can't do operations like add them togethet, java saies that operator += is undefined for the type. But as far as I know the number classes are all inherited from the abstract Number class. Is there a way to do something like this, or do I have to create Vector3f, i, d, and so on manually?

Jon Skeet
people
quotationmark

But as far as I know the number classes are all inherited from the abstract Number class.

Yes, but that's completely irrelevant when it comes to operators.

You can't add operators overloads in Java at all, regardless of whether your type extends Number.

people

See more on this question at Stackoverflow