What you're looking to do isn't a simple conversion from
Boolean, what you're trying to do here is to take a
That's an entirely different beast (than variable casting), and not one that Apex is meant to handle.
The gist of the comments and answers on those questions are that this is not something Apex does. If you're adamant about doing this, there are methods, but none are particularly easy or clean.
- Make a callout from your code to the REST API so you can run your string as anonymous apex
- Attempt to push this work off to Javscript so you can use its
- Build a simple evaluation engine in Apex that can handle things provided in reverse polish notation (i.e.
[+, 4, 5], which would result in