Jump to content
  • Advertisement
Sign in to follow this  
Cacks

[java] Generic matrices

This topic is 3883 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi Guys, I want to be able to instanciate a matrix using any number type using generics. However, I want to store my matrix elements in an array but java 6 will not permit me to write; T matrixElements[] = new T[16]; Im using JOGL as my graphics API so I want to be able to pass matrixElements[] to JOGL functions. Any1 have any advise, maybe some other way of doing this? Cheers

Share this post


Link to post
Share on other sites
Advertisement
Java generics are useless, especially for things like that. It also can't be done.

There has been a lot of criticism with regard to them, but there's very little hope Sun will ever get around to making them useful.

Right now, they're just fancy type-casting mechanism.

For matrix, you can simply forget doing that. Each of your matrix elements will need to be an object, and boxed primitive types are immutable. Each time you perform any operation between two elements, you'll need to allocate new result.

Overall, generics in Java are an unfortunate bastard child of trying to cater to everything, and delivering nothing. But yea, using your List no longer requires you cast the results.

They're just syntactic sugar, with no real benefits to language itself.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!