Advertisement
Guest User

Lispnik

a guest
Jun 9th, 2009
41
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.89 KB | None | 0 0
  1. // with instance of checked
  2.  
  3. public class Example {
  4.     private String foo;
  5.     private int bar;
  6.     public String getFoo() {
  7.         return foo;
  8.     }
  9.     public void setFoo(String foo) {
  10.         this.foo = foo;
  11.     }
  12.     public int getBar() {
  13.         return bar;
  14.     }
  15.     public void setBar(int bar) {
  16.         this.bar = bar;
  17.     }
  18.     @Override
  19.     public int hashCode() {
  20.         final int prime = 31;
  21.         int result = 1;
  22.         result = prime * result + bar;
  23.         result = prime * result + ((foo == null) ? 0 : foo.hashCode());
  24.         return result;
  25.     }
  26.     @Override
  27.     public boolean equals(Object obj) {
  28.         if (this == obj)
  29.             return true;
  30.         if (obj == null)
  31.             return false;
  32.         if (!(obj instanceof Example))
  33.             return false;
  34.         Example other = (Example) obj;
  35.         if (bar != other.bar)
  36.             return false;
  37.         if (foo == null) {
  38.             if (other.foo != null)
  39.                 return false;
  40.         } else if (!foo.equals(other.foo))
  41.             return false;
  42.         return true;
  43.     }
  44.    
  45.    
  46. }
  47.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement