Re: Generators for the other Joe-E array types

"Tyler Close" <[email protected]>
Newsgroups gmane.comp.lang.e.general
Message-ID <[email protected]>
Hi David,

On Dec 15, 2007 9:30 PM, David Wagner <[email protected]> wrote:
> You mentioned that you wanted to eliminate all unsafe casts.  The
> interface above may require casting the return value of snapshot()
> to the appropriate subtype of ConstArray.  For example, consider the
> following usage:
>     Generator<T> g = PowerlessArray.generate(n);
>     ...
>     PowerlessArray<T> a = (PowerlessArray<T>) g.snapshot();
> The last line requires an unchecked cast.  Is that okay?  Would you
> prefer to have the interface be designed to be statically type-safe?
>
> For example, would the following alternative be better?
>     interface Generator<A extends ConstArray<T>,T> {
>         void append(T value);
>         A snapshot();
>     }
> Each Joe-E array type would provide a generate() method that returns
> the appropriate type; e.g., PowerlessArray<T>.generate()'s return type
> would be Generator<PowerlessArray<T>,T>.  That would eliminate the
> need to cast the return value of Generator.snapshot() to the appropriate
> array type.  Does this seem like an improvement?

I was thinking PowerlessArray would provide a public implementation of
the Generator interface and make use of Java's support for covariant
return types in the implementation of the snapshot() method, so...

    public final class
    Generator<T> implements org.joe_e.array.Generator<T> {

        ...
        public PowerlessArray<T>
        snapshot() { return ...; }
    }

Use would then be:

    PowerlessArray.Generator<T> g = PowerlessArray.generate(n);

    PowerlessArray<T> a = g.snapshot();

This is similar to how the ByteArray.Generator class currently works.

--Tyler

-- 
The web-calculus is the union of REST and capability-based security:
http://www.waterken.com/dev/Web/

Name your trusted sites to distinguish them from phishing sites.
https://addons.mozilla.org/firefox/957/
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.