I think that the following should be okay:

public boolean equals(Object o) {
    try {
        UserListPK in = (UserListPK)o;
        return ( userID.equals(in.userID) && listID.equals(in.listID) );
    } catch (ClassCastException e) {
        return false;
    }
}
++Jeff


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....
> thanx
> 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;
>     }
> 
>  public UserListPK(String userID,String listID)
>  {
>         this.userID = userID;
>         this.listID = listID;
>  }
> 
>    public boolean equals()
>   {
>     what code should I have here..........
>    }
> 
> 
> }
> 
> 
> 
> --
> --------------------------------------------------------------
> To subscribe:        [EMAIL PROTECTED]
> To unsubscribe:      [EMAIL PROTECTED]
> List Help?:          [EMAIL PROTECTED]
> 
> 
> 
> 



--
--------------------------------------------------------------
To subscribe:        [EMAIL PROTECTED]
To unsubscribe:      [EMAIL PROTECTED]
List Help?:          [EMAIL PROTECTED]

Reply via email to