0

I want to convert a Vector3f array directly from array to another kind of data. Here is an example:

Vector3f[] vecArray = new Vector3f[10];
float[] floatArray = vecArray.toFloats(); // <<

Is that possible ?

1
  • Java provides toArray() but you usually have to use the wrapper Float (or Double, etc). You can write a method to do it but the syntax would look different from what you posted. Also an array of Vector3f(s)? Start with how you might represent one Vector3f as a single float. Commented Oct 4, 2014 at 13:34

1 Answer 1

1

No, there's nothing you can do to make that compile. (There's no equivalent of the extension methods in C# which would allow it, for example.)

The closest you'd be able to come would be to have a static method somewhere - whether within Vector3f or not - which you could invoke with a static import potentially:

import static ...Vector3f.toFloats;

Vector3f[] vecArray = new Vector3f[10];
float[] floatArray = toFloats(vecArray);
Sign up to request clarification or add additional context in comments.

1 Comment

Yeah that should be ok. Thank you mate :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.