Github user StephanEwen commented on the pull request:
https://github.com/apache/incubator-flink/pull/85#issuecomment-50667122
I found a good way to detect lambdas. It only works if the SAM interface is
serializable, but ours are always.
The trick is to search for the `writeReplace` method from serializable
objects and see whether it returns a `SerializedLambda`.
```
public interface LambdaFunction extends java.io.Serializable {
String doComputation(Integer value);
}
public static void main(String[] args) throws Exception {
LambdaFunction func = (theInteger) -> "string " +
String.valueOf(theInteger);
for (Class<?> clazz = func.getClass(); clazz != null; clazz =
clazz.getSuperclass()) {
try {
Method replaceMethod = clazz.getDeclaredMethod("writeReplace");
replaceMethod.setAccessible(true);
Object serializedForm = replaceMethod.invoke(func);
if (serializedForm instanceof SerializedLambda) {
SerializedLambda sl = (SerializedLambda) serializedForm;
System.out.println(sl);
break;
}
}
catch (NoSuchMethodError e) {
// fall through the loop and try the next class
}
catch (Throwable t) {
t.printStackTrace();
return;
}
}
}
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---