Java - convert predicate to string

I would like to know if there is a way to convert Predicate to String . For example, there will be a function:

 public static <T> String convertPredicate(Predicate<T> objPredicate) { return ?... } 

So that the next call returns (obj) -> obj.value== 1 :

 convertPredicate((obj) -> obj.value== 1) 
+7
java string lambda predicate
source share
1 answer

No, in general, this is not possible in Java. You can try to analyze and decompile the bytecode of the lambda class (although getting the bytecode of this class is already a really non-trivial task), but such a solution would be very complicated and fragile. The specific representation of lambda is not specified at runtime and may change in different versions of Java or different JDK providers.

+6
source share

All Articles