Instead of trying to trying to put my problem into words, here’s some code that demonstrates what I want to do:
Class cls = Double.class
String str = "31.4";
Comparable comparableObj null;
comparableObj = (Comparable) cls.cast(str);
Any ideas? I’ve looked at using reflection but with no success.
I really don’t like what you are trying to do, but here is my modification of your code so that it compiles and runs:
Prints:
It might help though if you explain in words what you are trying to achieve, then you might get more help doing it a better way.