static implemetation of interface method

Discussion in 'Java' started by Timo Nentwig, Mar 8, 2005.

  1. Timo Nentwig

    Timo Nentwig Guest

    Hi!

    Why actually can a interface method implementation not be static?

    public interface IF
    {
    public /* static */ void method();
    }

    public class Test implements IF
    {
    public /* static */ void method()
    {
    }
    }
     
    Timo Nentwig, Mar 8, 2005
    #1
    1. Advertising

  2. Timo Nentwig wrote:
    >
    > Hi!
    >
    > Why actually can a interface method implementation not be static?


    I'll just give you the simple explanation. An interface can only be used two ways:

    + As something another interface extends or a class implements.

    + As an interface reference.

    Ignoring Java's kludge in that area, a reference can only actually be used to refer to
    instance methods and fields. In addition, having interface static methods would conflict
    with the Java rules for static members. What would <inteface-name>.staticMethod() mean?
    Where would it find the implementation? What about multiple inheritance of interfaces?

    IOW, it would cause big problems, not unlike the proposal for specifying constructor
    signatures in an interface. That's some of the reasons why Java doesn't support it.

    --
    Lee Fesperman, FFE Software, Inc. (http://www.firstsql.com)
    ==============================================================
    * The Ultimate DBMS is here!
    * FirstSQL/J Object/Relational DBMS (http://www.firstsql.com)
     
    Lee Fesperman, Mar 9, 2005
    #2
    1. Advertising

  3. Timo Nentwig

    Chris Uppal Guest

    Timo Nentwig wrote:

    > Why actually can a interface method implementation not be static?


    What /exactly/ are you wanting to be able to do ?

    An interface defines (part of) a contract that an object will meet by having
    implementations of the various methods named by the interface. So what would a
    static method mean ? It couldn't be part of the implementation of the
    interface, because the static method (by definition) is not attached to any
    object.

    -- chris
     
    Chris Uppal, Mar 9, 2005
    #3
  4. Timo Nentwig wrote:
    > Why actually can a interface method implementation not be static?
    >
    > public interface IF
    > {
    > public /* static */ void method();
    > }
    >
    > public class Test implements IF
    > {
    > public /* static */ void method()
    > {
    > }
    > }


    Because static methods cannot be overridden by child classes, they're
    attached to the defining class and not to any instances.

    --
    Darryl L. Pierce <>
    Visit my homepage: http://mcpierce.multiply.com
    "By doubting we come to inquiry, through inquiry truth." - Peter Abelard
     
    Darryl Pierce, Mar 13, 2005
    #4
    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. anupam

    CORDIC implemetation

    anupam, Dec 1, 2005, in forum: VHDL
    Replies:
    2
    Views:
    764
    anupam
    Dec 2, 2005
  2. pete kirkham
    Replies:
    0
    Views:
    3,434
    pete kirkham
    Jun 27, 2003
  3. hg
    Replies:
    10
    Views:
    601
  4. Prafulla T

    Java 2 ME Implemetation problem..

    Prafulla T, Aug 12, 2007, in forum: Java
    Replies:
    0
    Views:
    337
    Prafulla T
    Aug 12, 2007
  5. News123
    Replies:
    0
    Views:
    693
    News123
    Jun 26, 2009
Loading...

Share This Page