class Fruit { class Seed {} // Not static, because this.outer is necessary } class Apple: Fruit { class RedAppleSeed: Fruit.Seed {} class GreenAppleSeed: Fruit.Seed {} } DMD 2.059: Error: class main.Apple.RedAppleSeed is nested within Apple, but super class Seed is nested within Fruit Error: class main.Apple.GreenAppleSeed is nested within Apple, but super class Seed is nested within Fruit
Indeed. The following is valid Java code and I would have expected it to work with D too as D took the Java way for OOP. class Fruit { class Seed { } } class Apple extends Fruit { class AppleSeed extends Fruit.Seed { Apple getOuter() { return Apple.this; } } } class Main { public static void main(String[] args) { final Apple apple = new Apple(); final Apple.AppleSeed appleSeed = apple.new AppleSeed(); assert (appleSeed instanceof Fruit.Seed); assert (apple == appleSeed.getOuter()); assert (appleSeed.getOuter() instanceof Apple); assert (appleSeed.getOuter() instanceof Fruit); } }
*** This issue has been marked as a duplicate of issue 1175 ***
So this is a regression? I am using this feature in my Android Java code too.