Consider the following code:
Object obj = {};
This results in the following error:
Type mismatch: cannot convert from Object[] to Object
However, according to the Java standard every Array is an Object:
In the Java programming language, arrays are objects (§4.3.1), are dynamically created, and may be assigned to variables of type Object (§4.3.2). All methods of class Object may be invoked on an array.
Besides that, the following snippet compiles without any problems:
Object [] arr = {};
Object obj = arr;
Question: what am I missing in the first code sample, i.e. why is not it valid?
P.S.: I'm almost sure that somebody already asked this question, because it seems so basic. However, I could not find any useful results neither here, nor in Google (maybe because square brackets are ignored in the search?). If there is a duplicate, which I missed, then please feel free to close my question. For the records, I checked the following questions. While their title seemed promising, they were all dealing with other kinds of issues, or did not contain the answer to my question: