I've got to maintain some code written by someone else who is no longer with the company. I'm seeing several references to java.lang.reflect.Array.getLength(anArray)
. Its working, but I've never seen reflection being used to get an array length. Does anyone know the difference between:
java.lang.reflect.Array.getLength(anArray)
and
anArray.length
Is it just syntactic sugar?
Thanks!
If anArray
is statically typed to an array type, you should use anArray.length
(not a method call, btw). You'd use the reflection form if you only had a reference to the array as Object
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With