Re: Java 8 and type erasure
Posted by
Stephan Ewen on
Aug 18, 2015; 11:46am
URL: http://deprecated-apache-flink-user-mailing-list-archive.369.s1.nabble.com/Java-8-and-type-erasure-tp2411p2424.html
Hi Kristoffer!
I looked through the code as well. In fact, Flink currently uses the trick mentioned for Serializable Lambdas in the gist you sent me.
This works well for lambdas that return simple types (primitives or classes without generics). The information for the generic parametrization is unfortunately really erased, it is in no signature or anything.
Java has the concept of "generic method signatures", which means that a method gets a signature string that includes the generic types. These signatures are generated for regular functions, but OpenJDK and OracleJDK do not generate them for synthetic methods (like lambdas).
We tried to submit a patch to OpenJDK to add these generic signatures to lambda methods, but they did not like the fact that we try to figure out the generic types of lambdas. I hope they change their minds at some point...
Stephan