It's not as far as you think it is :) see https://bitbucket.org/jpilliet/android-292
HN user
falloutfar
Hi Benji, there is a way to avoid CGlib proxy for what you want to do. It's clearly a hack but I think it's a better hack than using CGlib because it doesn't require code generation.
By default, a method reference or a lambda doesn't carry a reflective description of itself to be lightweight. This description is generated by the compiler, pass to the metafactory but once the method reference object is created the recipe of the method reference is lost. That is true but in one case, if the lambda or the method reference is Serializable, in that case, the recipe need to be kept in order that the runtime can deserialize the method reference. There are several ways to force a method reference to be serializable, the easiest way is to declare the functional interface that will receive the method reference as inheriting from Serializable. This means you can not use java.util.function.Function, you have to create your own interface that inherits from Serializable. Once you have done that, you just have to serialize the method reference to an array and deserialize it by hand to extract the recipe. So the only thing you need is a code that simulate de-serialization withtout using the classical ObjectInputStream of Java because it will not let you sneak at the recipe. The code here [1], do what you want.
cheers,
[1] https://github.com/forax/jayspec/blob/master/jayspec/src/com...
it uses an old hardware, with an old JDK, etc.