cobolstinks cobolstinks - 1 year ago 163
Java Question

java java.lang.reflect.Array.getLength vs array.length

I've got to maintain some code written by someone else who is no longer with the company. I'm seeing several references to

. Its working, but I've never seen reflection being used to get an array length. Does anyone know the difference between:



Is it just syntactic sugar?


Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download