I need to be able to have an n-dimensional field where n is based on an input to the constructor. But I’m not even sure if that’s possible. Is it?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Quick solution: you could approximate it with a non-generic
ArrayListofArrayListof … going as deep as you need to. However, this may get awkward to use pretty fast.An alternative requiring more work could be to implement your own type using an underlying flat array representation where you calculate the indexing internally, and providing accessor methods with vararg parameters. I am not sure if it is fully workable, but may be worth a try…
Rough example (not tested, no overflow checking, error handling etc. but hopefully communicates the basic idea):