Why doesn't Java have method delegates?

后端 未结 9 1504
再見小時候
再見小時候 2021-02-05 17:42

The Java gurunaths (natha नाथ = sanskrit for deity-master-protector) at Sun should condescend to accept the necessity of delegates and draft it into Java spec.

In C#, I

9条回答
  •  隐瞒了意图╮
    2021-02-05 18:15

    In Java, you have inner classes, which are tied to one particular instance of the parent class and have direct access to its members. Thus, implementing an inner class does not require (much) more code than writing a method.

    C# does not have inner classes. Both inner classes (like in Java) and delegates (like in C#) have their advantages (sometimes I miss inner classes in C#), but from a language designer point of view it makes sense to stick to either one of them (rather than supporting both), since this makes the class library design more consistent.

提交回复
热议问题