I would like to know if there is any way to convert a Predicate
to String
. For example there will be a function:
public static <T> String convertPredicate(Predicate<T> objPredicate) {
return ?...
}
So that the following call will return (obj) -> obj.value== 1
:
convertPredicate((obj) -> obj.value== 1)
No, in general it's not possible in Java. One may try to analyze and decompile the bytecode of the lambda class (though obtaining the bytecode of this class is already really non-trivial task), but such solution would be really complex and fragile. Particular runtime representation of the lambda is not specified and may change in different Java versions or different JDK vendors.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With