Tagging Interfaces in Java

前端 未结 8 2087
时光说笑
时光说笑 2021-01-02 06:26

What are tagging interfaces and what are they used for?

相关标签:
8条回答
  • 2021-01-02 06:58

    The question of marker interfaces vs annotations is discussed in Bloch's "Effective Java", and part of that section is available on google books here

    0 讨论(0)
  • 2021-01-02 07:06

    I would also add you can use tagging interfaces to restrict ownership of an instance:

    interface IFlumThing;
    interface IFlooThing;
    
    class BaseThing {...}
    
    class FlumThing extends BaseThing implements IFlumThing {};
    class FlooThing extends BaseThing implements IFlooThing {};
    
    class Flum {
       addThing(IFlumThing thing){...};
    }
    
    class Floo {
       addThing(IFlooThing thing){...};
    }
    
    0 讨论(0)
提交回复
热议问题