In my code, I have a Vector class that looks like this:
class Vector<N extends number> {...}
N represents the size or dimension of the vector. This Vector class also includes a cross product method to calculate the cross product between vectors:
cross(vector: Vector<N>) {...}
The issue is that the cross product method is only valid for vectors with 3 dimensions (N extends 3). So, my question is: Is there a way to prevent other vectors from accessing the cross product method, except for those with exactly 3 dimensions? I would prefer not to use a subclass such as 3DVector specifically for implementing the cross product method. One solution I considered is:
cross(vector: N extends 3 ? Vector<3> : never) {...}
However, this solution does not completely hide the method but rather disables it by setting the parameter to never. Can you suggest a better approach to solve this problem more effectively?