浏览 1971 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
|
|
---|---|
作者 | 正文 |
发表时间:2007-09-06
public interface Ia<E> { public void add(E element); public E get(); } I can implement it like: 1. public class A implements Ia { public void add(Object element) { } public Object get() { return null; } } 2. public class A implements Ia<Object> { public void add(Object element) { } public Object get() { return null; } } 3. public class A<F> implements Ia<F> { public void add(Object element) { } public F get() { return null; } } 4. public class A<F> implements Ia<F> { public void add(F element) { } public F get() { return null; } } IMO, all implementations above are valid, but: * implementation 1 treat generic as old code before generic imported into Java, compiler will give a warning on it, but at least it's clear to most of all * implementation 2 is weird in fact, it's same with implementation 1, but it will give a shock to user * implementation 3 use generic interface in a not bad way, but it use Object on one of methods prototype, and I don't think it's better for user either * implementation 4 use generic interface in a right way What's your insight? 声明:ITeye文章版权属于作者,受法律保护。没有作者书面许可不得转载。
推荐链接
|
|
返回顶楼 | |
发表时间:2007-09-07
Hi, Boy! What do you wanna express?
|
|
返回顶楼 | |
发表时间:2007-09-07
movingboy 写道 Hi, Boy! What do you wanna express? you don't understand? that's why I post this notes
|
|
返回顶楼 | |