On Sun, Feb 8, 2009 at 2:40 PM, Weiqi Gao <[email protected]> wrote:

>
> [email protected] wrote:
> > This is the first time I've felt the need to change the language. I
> > guess everybody else here wants other changes. I've got this class in
> > every project I've worked on for the last 2 years. Anybody has a
> > better one?
>
> public class Pair {
>   public Object first;
>   public Object second;
> }
>

public final class Pair<T,Z>
{
    public final T _1;
    public final Z _2;

    public Pair(final T _1,final Z _2)
    {
          this._1 = _1;
          this._2 = _2;
    }
}


>
>
> > public class Par<P extends Serializable, Q extends Serializable>
> > implements Serializable {
> >
> >     static final long serialVersionUID = 9L;
> >
> >     private P car;
> >     private Q cdr;
> >
> >     public Par(P car, Q cdr) {
> >         this.car = car;
> >         this.cdr = cdr;
> >     }
> >
> >     public P getCar() {
> >         return car;
> >     }
> >
> >     public Q getCdr() {
> >         return cdr;
> >     }
> >
> >     @Override
> >     public boolean equals(Object obj) {
> >         if (obj == null) {
> >             return false;
> >         }
> >         if (getClass() != obj.getClass()) {
> >             return false;
> >         }
> >         @SuppressWarnings("unchecked")
> >         final Par<P, Q> other = (Par<P, Q>) obj;
> >         if (this.car != other.car && (this.car == null || !
> > this.car.equals(other.car))) {
> >             return false;
> >         }
> >         if (this.cdr != other.cdr && (this.cdr == null || !
> > this.cdr.equals(other.cdr))) {
> >             return false;
> >         }
> >         return true;
> >     }
> >
> >     @Override
> >     public int hashCode() {
> >         int hash = 9;
> >         hash += 97 * hash + (this.car != null ? this.car.hashCode() :
> > 0);
> >         hash += 97 * hash + (this.cdr != null ? this.cdr.hashCode() :
> > 0);
> >         return hash;
> >     }
> > }
> >
> > >
>
>
> --
> Weiqi Gao
> [email protected]
> http://www.weiqigao.com/blog/
>
> >
>


-- 
Viktor Klang
Senior Systems Analyst

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "The 
Java Posse" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/javaposse?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to