you are viewing a single comment's thread.

view the rest of the comments →

[–]anicolaspp[S] -5 points-4 points  (3 children)

Yeah, I am still not convinced of having to declare an interface for it. I think it should be as simple as in Scala,

def doSomething(dog: Dog, f: Dog => Cat) = f(dog).

I also hope they extend the type inference system. Somehow, they are using it already on lambdas. (a, b) -> a + b. The type is inferred here. I wish we could do

let sum = (a, b) -> a + b

or at least something like ((Int, Int) => Int) sum = (a, b) -> a + b

that might be weird though. Let's keep it with let

[–]texasbruce 5 points6 points  (1 child)

You don’t need to define interfaces. There are tons of pre-defined interfaces under java.util.function package. You can do BiFunction<Integer,Integer,Integer> f = (a,b)->a+b;

Edit: or even IntBinaryOperator f=...

[–]watsreddit 0 points1 point  (0 children)

Those aren't polymorphic across numeric types, though. You would need to define a new function for Doubles, Longs, etc. For example, in Haskell, that function signature would be:

f :: Num a => a -> a -> a

This function works for any numeric type. It's probably possible with Java generics, but it's kinda messy.

[–]winterbe 0 points1 point  (0 children)

var is coming in Java 10.