int[] arr = {1, 2, 3};
arr = {1, 2, 3} //Error
arr = new int[] {1, 2, 3}; //No Error
So my question is, why is that so? I mean wheres the difference between line 2 and line 3?
int[] arr = {1, 2, 3};
arr = {1, 2, 3} //Error
arr = new int[] {1, 2, 3}; //No Error
So my question is, why is that so? I mean wheres the difference between line 2 and line 3?
That is how java or C# works buddy, can't really complain on this.. if we come to programming language semantics, line 2 introduces some ambiguity which is not really desired, and if we think about the really advanced stuff like the parse tree that needs to be constructed for a statement like the line 2, we are running into great trouble.
read some thing about parsers if you like link to parse trees