The Java compiler (javac) does not perform such kind of optimizations. In fact, as indicated in Optimization by Java Compiler, it only performs little optimizations in order to let all available information to the JIT compiler.
So if you declare some lambda as Function<Double,Integer>
, the bytecode will represent it as such – well, with its raw type, Function
.
Now, depending on the context and execution load of that portion of code, the JIT compiler might be able to inline the lambda (or other implementation of that Function
) and produce very similar or even identical machine code to what it would produce with the DoubleToIntFunction
version.
Note that in that case, the type information disappears entirely. It does not replace one with another.