We did they make the decision to not implement a toString method for int[], but instead let it inherit the toString method from Object?
We did they make the decision to not implement a toString method for int[]
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
They did implement more reasonable
toStringmethods for arrays. They are located in thejava.util.Arraysclass.As for reasoning. I’m assuming by the overrides provided in the
Arraysclass, that trying to implement a generictoStringfor different types of arrays is either complex or impossible. ThetoStringmethod would have to know what type of array it was working on, and output the data approrpiately. For instance,Object[]must usetoStringon each element, whilechar[]must output the character, and the numeric datatypes must be converted to a numeric string.The methods in
Arraysget this for free, because the types are fixed due to the overrides.