[2769] in java-interest
Re: AWT behavior
daemon@ATHENA.MIT.EDU (Jim Graham)
Fri Oct 13 00:10:11 1995
Date: Thu, 12 Oct 1995 19:23:44 -0700
From: flar@bendenweyr.Eng.Sun.COM (Jim Graham)
To: java-interest@java.Eng.Sun.COM, ser@jersey.uoregon.edu
> Since we're here, I'd like to ask if the decision not to have dynamically
> referenced objects was an oversight or deliberate. Let me give an example
> (I'm being liberal with the syntax, as I'm entering this on-the-fly):
>
> class point {
> public int x;
> public point(int g) { x=g; }
> public boolean eq(point p) { return x==p.x; }
> }
> class colorpoint extends point {
> public int c;
> public colorpoint(int g, int f) {
> super(g); c=f; }
> public boolean eq(colorpoint cp) {
> if (x==cp.x) return ci==cp.c;
> return false; }
> }
> class test {
> static final void main(String args[]) {
> point p;
> colorpoint r = new colorpoint(1, 2);
> p=r;
> /* Here's the funny part ******************************8*/
> p.equal(r); // calls point.equal, not colorpoint.equal
> System.out.println(String.newInstance(p==q));
> }
> }
Note that colorpoint.eq does not override point.eq since their
arguments are different so they are different methods. What
you want in colorpoint is:
public boolean eq(point p) {
return ((p.x == x)
&& (p instanceof colorpoint)
&& (((colorpoint) p).c == c));
}
...jim
-
Note to Sun employees: this is an EXTERNAL mailing list!
Info: send 'help' to java-interest-request@java.sun.com