I am trying to import the static members of Arrays class but it's conflicting with the some members in object class.
For example, I am trying to print the int array content using the toString static method in Arrays class, but the IntellijIDEA is telling me "Non-static member 'toString' can not be referenced from a static context."
If I follow the definition of toString method, IntelliIDEA takes me to toString method in Object class.
The code works if I use 'Arrays.toString' instead of 'toString'.
But how can I resolve the conflict without appending 'Arrays'?
Campbell Ritchie wrote:You can't. You have to write Arrays.toString(...)
Thank you. Can you tell me why the Object.toString is being prioritized over Arrays.toString?
posted 1 week ago
Afraid not; I looked in the JLS (=Java® Language Specification) and the imports section didn't help. I think members are called in the order
but I am not certain. Remember that toString() is the method in the same class/same object until proven otherwise. See if you can't find something about disambiguating names in the JLS. Because of the CapitalLettersConventions, the case of the identifier often resolves any possible conflict at compile time.