Marker Interface

Discussion in 'Java' started by lsrinu, Jun 6, 2006.

  1. lsrinu

    lsrinu Guest

    Why we need Marker Interface, It doesn't have any methods to implement
    , why we use empty interfaces, how it useful.
     
    lsrinu, Jun 6, 2006
    #1
    1. Advertising

  2. lsrinu

    jmcgill Guest

    lsrinu wrote:
    > Why we need Marker Interface, It doesn't have any methods to implement
    > , why we use empty interfaces, how it useful.
    >


    Good question. A marker interface provides a way to organize classes
    into categories, and derived classes all inherit those categories. Even
    though a marker interface does not specify behavior, it does very
    strongly specify a type, and that type can be checked by instanceof or a
    parameter declaration.

    The language designers could have made a requirement that interfaces
    specify methods, but that would have been an unneeded constraint. The
    marker interface is just a way to take advantage of the type
    identification that an interface provides, without declaring any behavior.

    Java does not, in my opinion, have the cleanest possible implementation
    of this pattern, since if a superclass is declared to implement an
    interface, a derived class cannot undo that. There are strong arguments
    either way, the other being that subclasses should always implement any
    interfaces of their superclasses. Very rare that it's a problem.
     
    jmcgill, Jun 6, 2006
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Brian Henry

    top level marker?

    Brian Henry, Dec 26, 2003, in forum: ASP .Net
    Replies:
    2
    Views:
    377
    Brian Henry
    Dec 27, 2003
  2. =?Utf-8?B?V2FubmFiZV9HZWVr?=

    Marker in ASP.Net

    =?Utf-8?B?V2FubmFiZV9HZWVr?=, May 13, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    631
    Alvin Bruney [MVP - ASP.NET]
    May 14, 2005
  3. Replies:
    6
    Views:
    35,550
    ksamir2004
    Jun 20, 2007
  4. -
    Replies:
    2
    Views:
    416
    Thomas G. Marshall
    Jul 12, 2005
  5. Replies:
    2
    Views:
    548
Loading...

Share This Page