> Hi,
>
[quoted text clipped - 30 lines]
> my feeling), how can we achieve something similar? If we use a method
> (say,join(), left()), please give me full implementation of the method?
Java does not allow user-defined overloading of operators. Even if it
did, I would argue against using + for anything other than addition of
numbers, - for anything other than subtraction of numbers etc. I've seen
C++ code that uses operators for arbitrary functions, and find it quite
unreadable.
For this sort of task in Java, I would design a class Team with methods
such as "add", "remove", "isMember", and possibly a method returning an
iterator over the members.
Team bestTeam = new Team();
bestTeam.add(person1);
bestTeam.add(person2);
bestTeam.add(person3);
bestTeam.remove(person3);
etc.
Inside bestTeam, I would use e.g. a java.util.Set, with implementing
class chosen based on the sort of operations, to remember the current
members.
Patricia
Shawn - 14 Sep 2006 16:13 GMT
> Java does not allow user-defined overloading of operators. Even if it
> did, I would argue against using + for anything other than addition of
[quoted text clipped - 19 lines]
>
> Patricia
Thank you very much. You have solved the doubts in my mind.