且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何调整Vala中Lambda表达式捕获的变量?

更新时间:2023-11-11 12:05:04

在lambda中,没有.标准方法是这样的:

Inside a lambda, no. The standard approach is this:

class Foo : Whatever {

  public Foo {
    unowned Foo unowned_this = this;
    this.bar_signal.connect(unowned_this.bar_handler);
  }
  private void bar_handler() {
    ...
  }
}

这不会捕获对此的引用,但是您也无法捕获任何其他变量.

This doesn't capture a reference to this, but you also cannot capture any other variables.