Wednesday, October 25, 2006

a note on generic array creation

new Scalar[numberOfRows][numberOfCols]will not work !!!

This is because the operator new is a run-time operation and Java 1.5 removes all generics typing at compile-time.

This is the well-known generic array creation, an operation not supported by Java 1.5.

You'd better use
(Scalar[][]) new Object[numberOfRows][numberOfCols]