Ulf Dittmer wrote:You can't, but he can - talk to him to find a mutually agreeable solution.
Sidharth Khattri wrote:
This can be because of the margin of error in float and double values, which does not return the exact value.
Since float and int is of 32 bits, for the second case, all the bits are used for the maximum value of int, hence for
float f=i;
float doesn't have to - add any precision bit values/or deal with the precision error. So, the down casted value in j will be same as the value in i, hence j==i is true.
While in the first case, since all the 32 bits are not utilized for the value in int i, conversion to float(also 32bit), i.e float f=i, will add some precision bits/or deal with the precision error, when value of "i" will be stored in f. So during down casting the casted value will not be same as the value in "i".
Though I'm not sure, this appears to be the correct reason. Waiting for more responses.
While assigning i to f, some information will be lost as value of type float are not precise to nine significant digits.
Sidharth Khattri wrote:
Andrea Binello wrote:
Astha Sharma wrote:Why does the code below generates StackOverflowError?
This is a bit tricky. When you do a get on a hash-table based map, the map must first calculate the hashCode of the key. In the above code, the key is the HashMap m2. The hashCode of HashMap (see source code of AbstractMap) is the sum of hash codes from all Entries. The Entry calculates its hashCode using hashCode of key and value. But one key is the map m2 (put just before) .... and so calculates the hashCode of m2 using all entries .... and this goes theoretically to the infinite ..... causing somewhere a StackOverflowError.
But there's nothing in m2, why would it infinitely calculate the hashcode for m2?
In this particular case, since the keys (i.e. the two Info objects) are unequal as per their equals() method and even though their hashcode are same, the HashMap will work properly for them. Both the objects will be stored and retrieved. However, the retrieval will fail only for Info objects that break the rule of equals() and hashCode() are put in the map.