java - This keyword with scala and anonymous functions/classes -


In Java, I can refer to the external example of a particular class: Sorry, I mean.

  Extend object obj to some class {def myMethodOfSomeInstance = {val uiThread = new SomeClass {def run}: unit = {chooser.showOpenDialog (SomeOtherClass.this)}}}  < / Pre> 

... this code does not compile, but on this line, I want to refer to the original example? How do i do this

chooser.showOpenDialog (SomeOtherClass.this)

You add an object to the attached object You can refer to the context of which you can specify:

  object SomeObject {outer = & gt; Def myMethodOfSomeInstance = {val uiThread = new SomeClass {def run}: Unit = {chooser.showOpenDialog (External)}}}}   

Edit: Anyway The object must be declared object obj for some other class extended scale code. Then you obj.this . can reference objects attached to it.

Comments