Sealed classes - would you want them in D?

Neia Neutuladh neia at ikeran.org
Sat May 12 04:29:32 UTC 2018


On Friday, 11 May 2018 at 14:05:25 UTC, KingJoffrey wrote:
> private is not private at all in D, and because of this, 
> classes are fundamentally broken in D (by design apparently).

I find this amusing because D does things exactly like Java. In 
Java, two sibling nested classes can call private functions on 
each other. But nobody says that this makes Java's classes 
fundamentally broken.

Like, this just works in Java:

public class Protections {
     public static class Bar {
         private void bar() { System.out.println("bar"); }
     }

     public static class Baz {
         private void bar(Bar b) { b.bar(); }
     }

     public static void main(String[] args) {
         new Baz().bar(new Bar());
     }
}

A function calling a private method defined in a different class, 
which calls a private function defined in yet another class! 
Utter madness! But the sky hasn't fallen, even though there's 
probably a thousand times as much Java code written as D.


More information about the Digitalmars-d mailing list