Reputation: 1673
how can i dynamically cast oject to a specific class which is given as a string. e.g.
def a = (ClassA) testService.getObject(xmlString)
i would like to do something like this
(grailsApplication.getClassForName(classString)) testService.getObject(xmlString)
but the groovy compiler does not like this way of cast operation.
Upvotes: 1
Views: 1879
Reputation: 11775
you could do
Class myClass = grailsApplication.getClassForName(classString)
myClass.cast testService.getObject(xmlString)
but I'm not sure how groovy
this way is - it's really just Java way..
Upvotes: 3