Last active
December 25, 2015 10:29
-
-
Save yareally/6961973 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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