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?
分享到:
相关推荐
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 ...
dos-iface.zip This is an example of how to use skins in your program, and also using BitBlt for a great looking interface.<END><br>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 ...
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 ...
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...
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 ...
<summary>The PropertyNameAttribute class is an attribute that is used to tag properties in API objects with a friendly name for use with the UI.</summary> <remarks>The StandardForms classes use the...
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 ...
- 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 ...
- **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 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 ...
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 ...
- **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....
04.zip How to use RecordSets without using the AppWizard at the creation of your project 不用AppWizard如何使用RecordSets(11KB)<END><br>5,05.zip Determine if DAO Jet engine version 3.5 is ...
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 ...