[1711] in java-interest

home help back first fref pref prev next nref lref last post

Re: Beta interface blues

daemon@ATHENA.MIT.EDU (Arthur van Hoff)
Thu Sep 14 22:45:29 1995

Date: Thu, 14 Sep 1995 16:02:33 -0800 (PDT)
From: Arthur van Hoff <Arthur.Vanhoff@Eng.Sun.COM>
Reply-To: Arthur van Hoff <Arthur.Vanhoff@Eng.Sun.COM>
To: "John D. Ramsdell" <ramsdell@linus.mitre.org>
Cc: java-interest@java.Eng.Sun.COM



Hi John,

> While updating a program to the Beta level syntax, I ran into a
> problem with interfaces.  I've constructed a general package for
> manipulating sets of elements.  The elements of the set have the
> requirement that they be ordered and testable for sameness.  There is
> no requirement that elements inherit from a common object other than
> Object.  In a version of sets for Alpha3, these requirements were
> defined using the following interface:
> 
> ------------
> package set;
> public interface Element {
>   boolean same(Element e); 
>   boolean less(Element e); // True when comparable and less than
> }
> ------------
> 
> Since a set can be an element of a set, the class Set implements an
> Element. 
> ------------
> package set;
> public final class Set implements Element {
>   private Pair p;	// Store elements in a list of pairs.
>   ....
>   public boolean same(Element e) {
>     return e != null
>       && e instanceof Set
> 	&& pair_same(p, ((Set)e).p);   // <- Cast in question
>   }
> 
>   private boolean pair_same(Pair p0, Pair p1) { .. }
> 
>   public boolean less(Element e) { ... }
> }
> -----------
> 
> The beta Java compiler rejects this code claiming it is illegal to
> cast an element to a set.  One solution is to define Element as an
> abstract class and require that all elements inherit from this class.
> However, I would like to allow sets of AppletElements, which inherit
> from Applet, simply by extending the Applet class with same and less
> methods.  My reading of The Java Language Specification suggests that
> the cast should be allowed.  Is this a bug?  If not, how does one
> construct a general set package?

This is a bug. I'll make sure it get fixed. Thanks for pointing it out.

Have fun,

	Arthur vanHoff

-
Note to Sun employees: this is an EXTERNAL mailing list!
Info: send 'help' to java-interest-request@java.sun.com

home help back first fref pref prev next nref lref last post