Java Delegates?(Java 代表?)
问题描述
Java 语言是否具有委托功能,类似于 C# 对委托的支持?
Does the Java language have delegate features, similar to how C# has support for delegates?
推荐答案
不是,不是.
你也许可以通过使用反射来获取可以调用的 Method 对象来达到相同的效果,另一种方法是使用单个invoke"或execute"方法创建一个接口,然后将它们实例化为调用您感兴趣的方法(即使用匿名内部类).
You may be able to achieve the same effect by using reflection to get Method objects you can then invoke, and the other way is to create an interface with a single 'invoke' or 'execute' method, and then instantiate them to call the method your interested in (i.e. using an anonymous inner class).
您可能还会发现这篇文章很有趣/有用:一位 Java 程序员看 C# 代表 (@blueskyprojects.com)
You might also find this article interesting / useful : A Java Programmer Looks at C# Delegates (@blueskyprojects.com)
这篇关于Java 代表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Java 代表?


- 从 finally 块返回时 Java 的奇怪行为 2022-01-01
- Java包名称中单词分隔符的约定是什么? 2022-01-01
- Spring Boot连接到使用仲裁器运行的MongoDB副本集 2022-01-01
- Jersey REST 客户端:发布多部分数据 2022-01-01
- value & 是什么意思?0xff 在 Java 中做什么? 2022-01-01
- Safepoint+stats 日志,输出 JDK12 中没有 vmop 操作 2022-01-01
- 将log4j 1.2配置转换为log4j 2配置 2022-01-01
- C++ 和 Java 进程之间的共享内存 2022-01-01
- Eclipse 插件更新错误日志在哪里? 2022-01-01
- 如何使用WebFilter实现授权头检查 2022-01-01