Hi!
Indika Fernando wrote:
> The following is my PrimaryKey class and I want to know how should I overide
> the equal() method and whether my code is correct
> can anyone propose me a good site to learn this stuff....
The EJB-INTEREST list is a good place to get general EJB questions
answered. There's a huge archive and subscription info at
archives.java.sun.com.
You might want to try theserverside.com as well.
> package com.web_tomorrow.user;
>
> // java core API
> import java.io.Serializable;
> public class UserListPK implements java.io.Serializable
> {
> public String userID;
> public String listID;
>
> public UserListPK(){}
>
> public int hashCode()
> {
> StringBuffer strBuff = new StringBuffer( );
> strBuff.append(userID);
> strBuff.append(listID);
>
> String str = strBuff.toString();
> int hashCode = str.hashCode( );
> return hashCode;
> }
Looks ok, although you will want to save the hashCode value so it is
only computed once.
> public UserListPK(String userID,String listID)
> {
> this.userID = userID;
> this.listID = listID;
> }
>
> public boolean equals()
> {
> what code should I have here..........
> }
public boolean equals(Object otherPk)
{
return ((UserListPK)otherPk).userId.equals(userId) &&
((UserListPK)otherPk).listId.equals(listId);
}
/Rickard
--
Rickard Öberg
Email: [EMAIL PROTECTED]
--
--------------------------------------------------------------
To subscribe: [EMAIL PROTECTED]
To unsubscribe: [EMAIL PROTECTED]
List Help?: [EMAIL PROTECTED]