Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Creating subclass of abstract class at runtime

 
amar nath jha
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I am cought in a problem .
Here is a scenario ---

We have an interface . User needs to provide implementation of methods in interface in an abstract class . Complete implementation will be provided dynamically at runtime and methods will be called on that implementation .

I am trying to achieve this but am not getting it . I tried this .But class implementation class FooImpl is not abstract . I want to create some thing like FooImpl at runtime .

Please provide me a sample code or some website links to help me achieve this.
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Amar,

why you want abstract class in this scenario? if you use abstract class ,how you will instantiate for dynamic methods implementation of interface

i mean some thing like this
--------------------------------------
Class.forName("foo.AbstractClass").newInstance();
--------------------------------------

correct me , if i am wrong
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As per your subjectline
------------------------------
Creating subclass of abstract class at runtime
--------------------------------

i think below one helps,


Hope this helps
 
Bill Shirley
Ranch Hand
Posts: 457
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
providing the implementation of a class at runtime is NOT a simple java procedure,

if you can, you will likely want to update to Java 6, which include much compiler support

java_6_compiler_api_tutorial

basically, you will have to compile a java class you compose, and load the resulting class with a class loader,

there are many other people providing equivalent functionality by hooking Java into some other language that facilitates scripting - Tcl, Python, JavaScript - I am not familiar with any of those, but suspect that may be a more productive route to take,
[ August 01, 2008: Message edited by: Bill Shirley ]
 
amar nath jha
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Bill

I am working on this url .

I think this would help me in generaing class and then we can load and compile it to make use of it .

Will reply very soon with the source code .





 
amar nath jha
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey I found one more link

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic