Skip to content

Instantly share code, notes, and snippets.

@linqing
Created June 4, 2013 03:43
Show Gist options
  • Save linqing/5703422 to your computer and use it in GitHub Desktop.
Save linqing/5703422 to your computer and use it in GitHub Desktop.
Call scala function in java
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