Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java - Convert predicate to string

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) 
like image 949
Omer Haimovich Avatar asked Nov 20 '15 14:11

Omer Haimovich


1 Answers

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.

like image 136
Tagir Valeev Avatar answered Sep 18 '22 10:09

Tagir Valeev