I get this when I call toString on an object I received from a function call. I know the type of the object is encoded in this string, but I don’t know how to read it.
What is this type of encoding called?
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.
[Ljava.lang.Object;is the name forObject[].class, thejava.lang.Classrepresenting the class of array ofObject.The naming scheme is documented in
Class.getName():Yours is the last on that list. Here are some examples:
The reason why the
toString()method on arrays returnsStringin this format is because arrays do not@Overridethe method inherited fromObject, which is specified as follows:Note: you can not rely on the
toString()of any arbitrary object to follow the above specification, since they can (and usually do)@Overrideit to return something else. The more reliable way of inspecting the type of an arbitrary object is to invokegetClass()on it (afinalmethod inherited fromObject) and then reflecting on the returnedClassobject. Ideally, though, the API should’ve been designed such that reflection is not necessary (see Effective Java 2nd Edition, Item 53: Prefer interfaces to reflection).On a more “useful”
toStringfor arraysjava.util.ArraysprovidestoStringoverloads for primitive arrays andObject[]. There is alsodeepToStringthat you may want to use for nested arrays.Here are some examples:
There are also
Arrays.equalsandArrays.deepEqualsthat perform array equality comparison by their elements, among many other array-related utility methods.Related questions