Created
June 4, 2013 03:43
-
-
Save linqing/5703422 to your computer and use it in GitHub Desktop.
Call scala function in java
This file contains 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
package chapter1 | |
object FunctionUtil { | |
def testFunction(f: Int => Int): Int = f(5) | |
val list = (1 to 100).toList | |
def filter(func: Int => Boolean): List[Int] = | |
list.filter(func) | |
} | |
abstract class AbstractFunction1ForJava[X, Y] extends (X => Y) { | |
} | |
// JavaFunction.java | |
public class JavaFunction { | |
public static void main(String[] args) { | |
AbstractFunction1ForJava func = new AbstractFunction1ForJava<Integer, Boolean>() { | |
public Boolean apply(Integer argument) { | |
return argument > 3 && argument < 8; | |
} | |
}; | |
System.out.println(FunctionUtil.filter(func)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment