[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 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/
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---