|
|
вернуться в форумThe 2nd sample Послано Zodiac 17 авг 2008 14:12 Why is the output 1? I think there're also three configurations to achieve the string, just as the 3rd sample: 1. second = new Object[1][1][0]; 2. Object level1 = new Object[1][0]; second = new Object[] { level1 }; 3. Object level2 = new Object[0]; second = new Object[] { new Object[] { level2 }}; Could anyone explain why the above three configurations should be considered as one? Re: The 2nd sample Because A[0]==A[0] <=> B[0]==B[0] <=> C[0]==C[0] and A[0][0]==A[0][0] <=> B[0][0]==B[0][0] <=> C[0][0]==C[0][0] and A[0][0][0]==A[0][0][0] <=> B[0][0][0]==B[0][0][0] <=> C[0][0][0]==C[0][0][0] '<=>' means equality of its boolean operands. '==' means 'equal-by-reference', i.e. they refer the same object. Objects are different if they were created by different 'new' statements or if they belong to different elements of the same 'new' statement. Assignments '=' during array creation modify references, but not objects. New objects are created only by 'new' statements. So, references within array are equal iff they trace back to the same element of the same 'new' statement. Otherwise they are different. Edited by author 09.09.2008 01:33 Edited by author 09.09.2008 01:34 |
|
|