How to transfer a fixed-length array to a method?

class A { final int length; void foo(Object[length] objects) {} // ? } 

    1 answer 1

    No You can only make all the values ​​of the array as separate parameters of the method:

     void foo(Object first, Object second, Object third) { } 

    You can also use the check of the length of the array with forwarding exceptions in the method body:

     void foo(Object[] objects) { if (objects.length != length) { throw new IllegalArgumentException("Incorrect array size"); } ... } 

    But this is a test, not a restriction.