Parameterizing the getter is definitely a valid option - possibly better than 
returning List<Object>, since it may help catch more errors at compile time.

G

On Jan 24, 2011, at 5:07 PM, calathus wrote:

> In order to avoid this compiler error issue, we may choose an approach to use 
> generic type for method level.
> see the following code. Although from type safety perspective, there are 
> quite strange things involved here..
> Originally I considered to use super(e.g, <? super I>) for anonymous type, 
> but looks like Java does support this syntax in quite restricted place.
> 
> 
> ----------------
> 
> public class Main {
> 
>     static class A {
>         List<?> ts;
>         public List<?> getList() {
>             return ts;
>         }
>         public void setList(List<?> ts) {
>             this.ts = ts;
>         }
>     }
>     interface I {
>         String getName();
>     }
>     static class B {
>         List<? extends I> ts;
>         public <T> List<T> getList() {
>             return (List<T>)ts;
>         }
>         public void setList(List<? extends I> ts) {
>             this.ts = ts;
>         }
>     }
> 
>     class J implements I {
>         String name;
>         public String getName() {
>             return name;
>         }
>         public void setName(String name) {
>             this.name = name;
>         }
>     }
> 
>     public static void main(String[] args) {
>         {
>             A a = new A();
>             a.setList(new ArrayList<Integer>());
>             List<Object> list = (List<Object>)a.getList();
>             //List<Object> list = a.getList(); // error
>         }
>         {
>             B b = new B();
>             b.setList(new ArrayList<J>());
>             List<I> list1 = b.getList();
>             List<J> list2 = b.getList();
>             List<Object> list3 = b.getList(); // OK
>             b.getList().add(new Integer(4));
>         }
>     }
> 
> }
> 
> 
> On Mon, Jan 24, 2011 at 12:45 PM, Greg Brown <[email protected]> wrote:
> > Another thought, ListView should not implement List interface? basically
> > a ListView/TableView are lists with an extra graphics support.
> 
> No, ListView and TableView are views on the model data provided by a List.
> 
> G
> 
> 
> 
> 
> 
> -- 
> Cheers,
> calathus
> 
> 
> 

Reply via email to