Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
243 views
in Technique[技术] by (71.8m points)

java - Is there a way to convert a LambdaExpression to a String

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


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

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
...