Create a multidimensional generic array of Optionals

I want to create a two-dimensional array (yes I know that this is actually an array of arrays) holding Optionals. The normal approach for generic array creation does not work though as it fails with a ClassCastException. Here is my code:

@SuppressWarnings("unchecked")

Optional[][] arr = (Optional[][]) new Object[5][5];

Is there a way to create such an array, if yes what would be the approach for that?...

Read More »

By: StackOverFlow - 6 days ago

Related Posts