I am creating & compiling(using ant script) java classes at runtime in my java program. In the same program I wanna get the objects for these classes and set their varibales/methods with some values.
Suppose I have a class like
From my main java program I can easily set or call the method of myclass like
The above code is trivial if we already know everything about "myclass". But if I want to get the instance of myclass at runtime & call methods of the class , I am totally confused & struck at this point, I can say
I suggest you read the concept of Reflection in detail... there are methods available for fetching the methods & variables...
Joined: Oct 04, 2011
The probelm here is to get methods of class & then invoke them using object. According to your solution we need to know that there is method called getVar present in the class, what if we dont have idea of what methods are present in the class?