Saturday, 31 August 2013

Java: How to make a final subarray?

Java: How to make a final subarray?

Consider the following snippet:
public class TestBench {
private static final short matrix[][] = new short[][] {new short[] {}};
public static void main (String args[]) {
matrix = new short[][] {new short[] {}}; // illegal
matrix[0] = new short[] {} // ok
}
}
Is there a way to make that sub array final? While reading the similar
questions, I realised I can do this with a custom class, but I'm curious
about using primitive types.
Thanks in advance.

No comments:

Post a Comment