Skip to content

Closures blocking out the surrounding scope for classes/instances #2

@vito

Description

@vito

An example, with the Android API:

hello = self
btn.setOnClickListener do
  def onClick(v)
    return if hello.txt.getText.toString.length == 0
    hello.addMessage("hellotester", Hello(v.getContext).txt.getText.toString)
    message = Bundle.new
    message.putString("say", Hello(v.getContext).txt.getText.toString)
    Message m = Message.obtain
    m.setData(message)
    hello.client.handler.sendMessage(m)
    hello.txt.setText("")
  end
end

hello is not accessible. Workaround here is to use Hello(v.getContext) (where Hello is the name of the class).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions