`
alexgreenbar
  • 浏览: 87704 次
  • 性别: Icon_minigender_1
社区版块
存档分类
最新评论

Is this a good/right way to use generic interface?

    博客分类:
  • Java
阅读更多
I have a generic interface like:
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?
分享到:
评论
2 楼 alexgreenbar 2007-09-07  
movingboy 写道
Hi, Boy! What do you wanna express?
you don't understand? that's why I post this notes
1 楼 movingboy 2007-09-07  
Hi, Boy! What do you wanna express?

相关推荐

    BobBuilder_app

    This format ensures a semi sorted key list, in that within a page the data is not sorted but pages are in sort order relative to each other. So a look-up for a key just compares the first keys in the ...

    VB编程资源大全(英文源码 表单)

    dos-iface.zip This is an example of how to use skins in your program, and also using BitBlt for a great looking interface.&lt;END&gt;&lt;br&gt;6 , sg_settings.zip This demonstrates how to save information ...

    计算机网络第六版答案

    We’ll be happy to provide a copy (up-to-date) of this solution manual ourselves to anyone who asks. Acknowledgments: Over the years, several students and colleagues have helped us prepare this ...

    Java Crash Course [2016]

    The best way to learn Java is by following a set of step by step, clear cut, uncomplicated lessons The problem? You might feel like you don't know where to start, or you may feel lost trying to read ...

    servlet2.4doc

    The doFilter method of the Filter is called by the container each time a request/response pair is passed through the chain due to a client request for a resource at the end of the chain. doGet...

    Requirements.Writing.for.System.Engineering

    Learn how to create good requirements when designing hardware and software systems. While this book emphasizes writing traditional “shall” statements, it also provides guidance on use case design ...

    NETCFSERUP

    &lt;summary&gt;The PropertyNameAttribute class is an attribute that is used to tag properties in API objects with a friendly name for use with the UI.&lt;/summary&gt; &lt;remarks&gt;The StandardForms classes use the...

    acpi控制笔记本风扇转速

    When this mode is specified, instead of creating a serialization semaphore per control method, the interpreter lock is simply no longer released before a blocking operation during control method ...

    jdk1.8_win32.rar

    - The Stream API provides a powerful new way to process collections, enabling functional-style operations such as filtering, mapping, and reducing. It significantly improves performance and ...

    Effective C#

    - **Purpose:** Delegates provide a way to pass methods as arguments, enabling callback mechanisms. - **Example:** ```csharp public delegate void ActionHandler(object sender, EventArgs e); public ...

    R for beginner

    R is an interpreted language that operates on a command-line interface. Users interact with R by entering commands, which are then executed directly without the need for compilation. This interactive ...

    Addison.Wesley.The.Java.Programming.Language.4th.Edition.Aug.2005.chm

    This book is not an introduction to object-oriented programming, although some issues are covered to establish a common terminology. Other books in this series and much online documentation focus on ...

    C++_CLI标准.pdf

    - **Enums**: Section 8.11 explains enums, which are a way to define named constants. - **Namespaces and Assemblies**: Section 8.12 discusses namespaces and assemblies, which are used to organize code....

    Visual C++ 编程资源大全(英文源码 数据库)

    04.zip How to use RecordSets without using the AppWizard at the creation of your project 不用AppWizard如何使用RecordSets(11KB)&lt;END&gt;&lt;br&gt;5,05.zip Determine if DAO Jet engine version 3.5 is ...

    The Art of Assembly Language Programming

    An Easy Way to Remember the 8086 Memory Addressing Modes 4.6.2.8 - Some Final Comments About 8086 Addressing Modes 4.6.3 - 80386 Register Addressing Modes 4.6.4 - 80386 Memory Addressing ...

Global site tag (gtag.js) - Google Analytics