pivot-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From calathus <calat...@gmail.com>
Subject Re: why ListButton.getListData returns List<?> ?
Date Tue, 25 Jan 2011 22:28:47 GMT
On Tue, Jan 25, 2011 at 12:31 PM, Greg Brown <gk_brown@verizon.net> wrote:

> > I think you do not write Java code using these API directly(relying on
> BXML), you would think the casting is not big deal.
>
> These APIs are typically used from code, not BXML - I just don't think that
> casting is a big deal in general. Sometimes it is necessary, especially when
> APIs are designed to be generic (like this one). But, like I said, it is
> easy enough to add a type parameter to the method to avoid the need to cast.
>

If the generic is something essential in the modeling, this type of cast
issue may be ignored.
But the use of anonymous type is just to accept some List<*> class as the
setter argument.
We may set different List<A.>, List<B> to the same instance of A, also we
may add any type of object.
A is designed to hold just List<Object>.
If we consider this way, enforced cast is very technical thing, should be
avoided.
Also the intended cast to List<J> is not type safe anyway. So such usage
itself is a bit tricky, maybe deserve for double
casting.(or getList(Class<T> cls).

The one suggested clint will not allow simple getList as default. List<?>
_getList() may be supported for a bit safer casting.

'A' should be implemented this way, avoid anonymous type in instance
property:

static class A {
        List<Object> ts;

        // new version
        public List<Object> getList() {
            return ts;
        }
        public <T> List<T> getList(Class<T> cls) {
            return (List<T>)ts;
        }
        public <T> void setList(List<T> ts) {
            this.ts = (List<Object>)ts;
        }

        public List<?> _getList() {
            return ts;
        }
        public void setList1(List<?> ts) {
            this.ts = (List<Object>)ts;
        }
    }


>
> > If you don't like to have two methods, it may just support List<Object>
> version. anyway we can alway cast to any type with double cast!
>
> Blech! That's even worse.  :-)
>
>
>
>


-- 
Cheers,
calathus

Mime
View raw message