Java does not support static method in interface. But sometimes, I just want a static method to say: PersistenceManager.getDefault(), where PersistenceManager is going to be an interface. I don't like to add one more class named PersistenceManagerFactory, with a method:
public static PersistenceManager PersistenceManagerFactory.getDefault()
So I write code like:
public class PersistenceManager {
private static I i;
public static I getDefault() {
return i == null ? i = ServiceLoader.load(I.class).iterator().next() : i;
}
/** The interface I, which is actually the PersistenceManager should be: */
public static interface I {
void saveQuotes(String symbol, Frequency freq, List<quote> quotes);
List<quote> restoreQuotes(String symbol, Frequency freq);
void deleteQuotes(String symbol, Frequency freq, long fromTime);
void dropAllQuoteTables(String symbol);
void shutdown();
QuotePool getQuotePool();
TickerPool getTickerPool();
}
}
Then implement the PersistenceManager.I in another package, like:
public class NetBeansPersistenceManager implements PersistenceManager.I {
...
}
And declare it under the META-INF as:
core/src/META-INF/services/org.aiotrade.math.PersistenceManager$I
which contains one line:
org.aiotrade.platform.core.netbeans.NetBeansPersistenceManager
I can call PersistenceManager.getDefault().showdown() now.
分享到:
相关推荐
attributeAdded(ServletContextAttributeEvent) - Method in interface javax.servlet.ServletContextAttributeListener Notification that a new attribute was added to the servlet context. attributeAdded...
Using Lambda Expressions in Code 41 Primitives 42 Overload Resolution 45 @FunctionalInterface 47 Binary Interface Compatibility 47 Default Methods 48 Default Methods and Subclassing 49 Multiple ...
The goal of this guide is to manage this complexity by describing in detail the dos and don'ts of writing C++ code. These rules exist to keep the code base manageable while still allowing coders to ...
PART I: CORE TECHNOLOGIES 1 Overview ...................................................................................................... 3 1.1 Introduction ............................................
code. AcpiEnable will now fail if all of the required ACPI tables are not loaded (FADT, FACS, DSDT). BZ 477 Added #pragma pack(8/4) to acobject.h to ensure that the structures in this header are ...
- Changed the mechanism to check for the required DirectX Direct3D as the previous method did not work on some system (some W2003 servers). - Enhanced the mechanism to report memory hardware errors ...
Part I Introduction ........................................................................................................................................39 1 Overview .................................
Available options (for this frontend in Zend_Cache factory) 4.3.6.3. Examples 4.4. Zend_Cache后端 4.4.1. Zend_Cache_Backend_File 4.4.2. Zend_Cache_Backend_Sqlite 4.4.3. Zend_Cache_Backend_...
oSavedFile.write(inc, 0, insize); } oSavedFile.close(); in.close(); } catch (HttpException e) { // 发生致命的异常,可能是协议不对或者返回的内容有问题 System.out.println("Please ...
stands for Internet Message Access Protocol, and is currently in version 4, also known as IMAP4. When using IMAP, your mail server must support the protocol. You can't just change your program to ...
With Sound ) A Very Cute Screen Saver ,with source code, If you want more avi files then please mail me.<END><br>36 , superwriter.zip A complete Wordprocessor, with source code. You can save, open ...
the HCs independent from the device specific code. - USB MSD: added support for disk image modes (like ATA disks) - USB printer: output file creation failure now causes a disconnect - re-...
(3) in addition, it cultivates our ability to consult and use manuals, atlas and other relevant technical data, as well as the ability in calculation, drawing data processing and computer, aided ...
* and redistributed in source or binary form, so long as an * acknowledgment appears in derived source files. The citation * should list that the code comes from the book "Linux Device * Drivers" ...
5.1 Overriding a Built-In Method 5.2 Getting All Members of a Class Hierarchy 5.3 Calling a Superclass _ _init_ _ Method if It Exists 5.4 Calling a Superclass Implementation of a Method 5.5 ...
(33KB)<END><br>36,noform.zip This sample shows how to make an application that doesn't have the doc/view architecture but still offers a form in the client area of the application's main window....
bridge.zip Bridge Pattern - Bridging the gap between Interface and Implementation (40KB)<END><br>76,method.zip Function Pointers to Non-Static Object Methods(24KB)<END><br>77,singleton.zip ...