[Issue 2524] final override inconsistent when implementing interfaces

d-bugmail at puremagic.com d-bugmail at puremagic.com
Tue Jan 20 15:15:19 PST 2009


http://d.puremagic.com/issues/show_bug.cgi?id=2524





------- Comment #10 from schveiguy at yahoo.com  2009-01-20 17:15 -------
But I can still cast to the interface.  Protection attributes are compile-time
entities, they are not flagged at runtime:

SoundManager s;
Object o = s;

INetworkListener inl = cast(INetworkListener)o;

The compiler just looks in the object's list of interfaces to see if it finds
that interface.  There is no protection associated with it at runtime.

What you are asking for requires a major compiler redesign for limited value. 
You can easily implement what you want using a private inner class:

interface INetworkListener {
    void acceptNetworkPacket();
}

class NetworkManager
{
    static void registerNetworkListener(INetworkListener listener) { ... }
}

class SoundManager
{
    private class NetworkListener : INetworkListener
    {
      void acceptNetworkPacket() {
        // ...
      }
    }

    this() {
        NetworkManager.registerNetworkListener(new NetworkListener);
    }
}

This is similar to how Java works with anonymous classes.  D can do the same
thing I think, but I can't remember the syntax right now.


-- 



More information about the Digitalmars-d-bugs mailing list