企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
方法可以通过 dynamic 关键字 使它们可绑定(重绑定): > Methods can be denoted with the dynamic keyword to make them (re-)bindable: ~~~ class Main { static dynamic function test() { return "original"; } static public function main() { trace(test()); // original test = function() { return "new"; } trace(test()); // new } } ~~~ 第一次调用 test() 调用了原来的函数,返回字符串 “original”。下一行,test被分配了一个新的函数。这恰恰是dynamic做到的:函数字段可以被分配一个新的函数。其结果是,下一次调用 test() 返回字符串 “new” 。 > The first call to test() invokes the original function which returns the String "original". In the next line, test is assigned a new function. This is precisely what dynamic allows: Function fields can be assigned a new function. As a result,the next invocation of test() returnsthe String "new". 动态字段因为明显的理由不能内联:内联是在编译时执行,动态函数必须被在运行时决定。 > Dynamic fields cannot be inline for obvious reasons: While inlining is done at compiletime, dynamic functions necessarily have to be resolved at runtime.