Re: Why interface cannot define static methods?
Ed wrote:
moop=99 skrev:
Hi.
As title, why?
Because the designers of Java decided that interfaces can't have static
methods.
You can easily achieve the effect of defining a static method in an
interface. Watch and learn:
==========================
===============
public interface MyStupidInterface
{
public static final Runnable stupidity = new java . lang . Runnable
( ) { public void run ( ) { System . out . println ( "Hello World!" ) ;
} } ;
}
==========================
===============
public class MyStupidApp implements MyStupidInterface
{
public static void main ( String [ ] args )
{
stupidity . run ( ) ;
}
}
==========================
===============
Is it possible to design a language with static interface methods (such
that concrete classes implementing that interface must declare those
methods as static)? Yip.
I think you are correct. I tried a variation of that. Is it
permissible to implement an interface using static methods? For
example using a static void run ( ) method to implement Runnable. It
is not permissible with my compiler. Why not, I don't know.
.ed
--
www.EdmundKirwan.com - Home of The Fractal Class Composition.
Download Fractality, free Java code analyzer:
www.EdmundKirwan.com/servlet/fractal/frac-page130.html