Skip to content

Instantly share code, notes, and snippets.

@yareally
Last active December 25, 2015 10:29
Show Gist options
  • Save yareally/6961973 to your computer and use it in GitHub Desktop.
Save yareally/6961973 to your computer and use it in GitHub Desktop.
/**
* Test converting a Java Interface to a Scala Lambda
* via implicits.
*
* @author Wes Lanning
* @version 2013-10-12
*/
class ConvertInterfaceTest extends Activity
{
// converts Java Runnable implmentation to Scala automagically
implicit def lambdaRun(funct: () => Unit) = new Runnable {
def run() = funct
}
override def onCreate(savedInstanceState: Bundle)
// the scala way using implicits to implement a Java interface as a lambda
runOnUiThread(() => {
// stuff to run on the ui thread
})
// the ugly java way to do the above
runOnUiThread(new Runnable {
def run() {
// stuff to run on the ui thread
}
})
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment