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...
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 ...
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 use of C51 microcontrollers in this design takes advantage of their built-in features, such as the programmable I/O ports, timers, and interrupts, which are essential for the operation of the LED ...
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 ...
- **Best Practice:** Initialize static fields in the constructor or inline. **Item 14: Minimize Duplicate Initialization Logic** - **Strategy:** Use patterns like the builder pattern to avoid ...
Files.write(tempFile.toPath(), sourceCode.getBytes()); // 设置编译任务 Iterable<? extends JavaFileObject> compilationUnits = fileManager.getJavaFileObjects(tempFile); compiler.getTask(null, file...
* 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" ...
foreach (MethodInfo method in methods) { Console.WriteLine("方法: " + method.Name); } Console.WriteLine("-----------------------"); } } } ``` 这段代码首先加载了一个名为"MyMath.dll"的程序集,...
(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 ...
// Code that might throw IOException or SQLException } ``` #### 二、JDK 8新特性概述 除了JDK 7中已经介绍的新特性外,JDK 8引入了许多重要的更新和改进,其中最突出的是Lambda表达式和Stream API的支持,...