Why doesn't Java have method delegates?

后端 未结 9 1529
再見小時候
再見小時候 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:20

    Delegates in C# look ugly to me. (declaring something as variable, and then adding () after it feels bad in OOP)

    Besides, if you want : "The delegate object can then be passed to code which can call the referenced method, without having to know at compile time which method will be invoked.

    you can simply use java.lang.reflect.Method

    Edit: As you said, using reflection is not a good approach. This is true, but using delegates, in an OOP perspective, is not a better approach, in my opinion. It is a functional-language construct.

提交回复
热议问题