Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I want to convert a LambdaExpression like pos -> pos.x < 5 && pos.y < 5 to a String which looks like this: "pos.x < 5 && pos.y < 5"

Is this possible in Java?

In C# I'm using something similar like this


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
255 views
Welcome To Ask or Share your Answers For Others

1 Answer

No, it's not possible.

Java is compiled to a set of bytecode instructions. The exact form of all Java source code, including that of lambdas, is lost at the point of compilation. It is a one-way process; certain details are irretrievably discarded (whitespace being one example, but there are other, less trivial ones) so you cannot recreate the source code from bytecode.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...