Java Mailing List Archive

http://www.gg3721.com/

Home » user.groovy »

[groovy-user] dynamic class creation

Joe Greenawalt

2010-03-16

Replies: Find Java Web Hosting

Author LoginPost Reply
Hi, i'm working on a grails project, but I think this is a groovy question.

Some background, I have a domain Company class, and I have and several SubCompany classes that inherit from Company

Certain Users only deal with certain "types" (subclasses) of companies.

So in writing a universal search for property values, i'd like to dynamically search different types of companies depending on the user.

Below is a basic example of what i'm trying to do although it could be way off.

class MyCompany extends Company{
 
 String getHi(){
   return "HI"
   }
}

def mc = "MyClass"

println $mc.getHi()

Can i dynamically instantiate a class through a variable name?


Thanks,
joe
©2008 gg3721.com - Jax Systems, LLC, U.S.A.