How to Determine Array Type Based on Signature
Based on Just Looking at the Signature, How Do You Determine If an Array Is Most Likely Perfect Sized or Oversized? I Know Perfect Sized Arrays Are Used When...
Based on just looking at the signature, how do you determine if an array is most likely perfect sized or oversized?
I know perfect sized arrays are used when the size of the array is known, otherwise an oversized array is used, but I don’t know how to determine (by looking at it) the array type based on a signature.
For example: public static void myMethod(int[] ray, int size)
Or: public static myMethod(int[] ray, boolean value)
1 Answer
Ok, I think I see your confusion.
Java array declarations never specify a size. An array variable can always be assigned arrays of different length.
Actual arrays at runtime will always have a fixed size, and the array itself know what that size is (the length field).
Java (the language) doesn't have the concept of perfect-sized or oversized arrays. That is only a concept for how the array is used.
Since an array knows it's own size at runtime, there is never a need to explicitly specify the size. A method that explicitly requires a size can work with over-sized arrays, because the explicit size parameter can be used to only process part of the array.
So, myMethod(int[] ray, int size) is a method that can work with oversized arrays.
myMethod(int[] ray, boolean value) can only work with perfect-sized arrays, because there is no way to detect partial usage of the array.