`
dcaoyuan
  • 浏览: 299854 次
社区版块
存档分类
最新评论

No Static Method in Interface, So I Write Code As ...

    博客分类:
  • Java
阅读更多

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.

分享到:
评论

相关推荐

    servlet2.4doc

    attributeAdded(ServletContextAttributeEvent) - Method in interface javax.servlet.ServletContextAttributeListener Notification that a new attribute was added to the servlet context. attributeAdded...

    Java 8 Lambdas

    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 ...

    Google C++ Style Guide(Google C++编程规范)高清PDF

    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 ...

    vxworks_kernel_programmers_guide_6.9

    PART I: CORE TECHNOLOGIES 1 Overview ...................................................................................................... 3 1.1 Introduction ............................................

    acpi控制笔记本风扇转速

    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 ...

    BURNINTEST--硬件检测工具

    - 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 ...

    JavaEE 5.0 Tutorial.pdf

    Part I Introduction ........................................................................................................................................39 1 Overview .................................

    ZendFramework中文文档

    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_...

    Interface的测试代码,请光临

    oSavedFile.write(inc, 0, insize); } oSavedFile.close(); in.close(); } catch (HttpException e) { // 发生致命的异常,可能是协议不对或者返回的内容有问题 System.out.println("Please ...

    Java邮件开发Fundamentals of the JavaMail API

    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 ...

    VB编程资源大全(英文源码 控制)

    With Sound ) A Very Cute Screen Saver ,with source code, If you want more avi files then please mail me.&lt;END&gt;&lt;br&gt;36 , superwriter.zip A complete Wordprocessor, with source code. You can save, open ...

    Bochs - The cross platform IA-32 (x86) emulator

    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-...

    二级减速器课程设计说明书reducer design specification.doc

    (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" ...

    Python Cookbook英文版

    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 ...

    Visual C++ 编程资源大全(英文源码 控件)

    (33KB)&lt;END&gt;&lt;br&gt;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....

    Visual C++ 编程资源大全(英文源码 网络)

    bridge.zip Bridge Pattern - Bridging the gap between Interface and Implementation (40KB)&lt;END&gt;&lt;br&gt;76,method.zip Function Pointers to Non-Static Object Methods(24KB)&lt;END&gt;&lt;br&gt;77,singleton.zip ...

Global site tag (gtag.js) - Google Analytics