I need to resolve this question, I trying to execute with reflection some methods of String class, like ‘reverse’ but is not possible. Do you know if there any way to execute this? . Thank you… ;).
This can’t be easily done, because reverse is not a method on String, it’s a method on StringOps. The system automatically wraps the String in a StringOps when you call reverse, but that’s not the same thing as it actually being a method of String.
What are you trying to do? This sort of reflection-based code is unusual in Scala; possibly there’s a better way to accomplish the same goal…
The “reverse” method you are attempting to reflect on is not a member of
java.util.String. It is a member of StringLike, which Scala makes available
on java.util.String using (I think) implicit conversions.
I was looking for to use something like “eval”, but scala don’t have support for this… Do you know if there any way to execute one method, of String for example, apart of reflection and obviously without to use the method directly
Correct – by and large, compiled languages (especially strongly-typed ones) are less likely to have “eval”-like capabilities. It’s not really what they are designed for.
Just one general warning: functionality like this can often leave gigantic security holes, especially if this code is exposed on the web. Use this sort of thing with a lot of care…