raja singh kumar wrote:
2. Is immutability acheived by making a class final?
raja singh kumar wrote:1. In the string method indexOf(int ch) why the signature of the method accepts an integer while the value passed is a character?
public int indexOf(int ch)
raja singh kumar wrote:1. In the string method indexOf(int ch) why the signature of the method accepts an integer while the value passed is a character?
public int indexOf(int ch)
raja singh kumar wrote:
3. Why type-casting is required when using the compareTo method of Comparable interface? Look at line 4 in below code. Who is passing Object class(or child class object) as an argument to the compareTo() method? Is it again related to something which is an internal implementation which we should not bother about?
raja singh kumar wrote:
2. Is immutability acheived by making a class final?
You mean that many people allow mutable reference types into/out of their object without defensive copies? Defensive copies is something often not taught to undergraduates.Junilu Lacar wrote:. . . I see many programmers do this kind of thing all the time . . .
Campbell Ritchie wrote:
You mean that many people allow mutable reference types into/out of their object without defensive copies? Defensive copies is something often not taught to undergraduates.Junilu Lacar wrote:. . . I see many programmers do this kind of thing all the time . . .
I was thinking about people writing code at all levels, so that would include professionals. If things are going to go wrong, a mutable reference type with multiple references is going to behave almost like a global variable. It is all a case of right first time. It might take a minute or so each time you take a defensive copy, but the hours and hours it takes to find these obscure bugs overwhelms any time saving there. Never mind the hazards of running buggy software.Junilu Lacar wrote:. . . No, I mean professional developers. Most of the time there aren't any serious consequences to not creating defensive copies of incoming data. . . .