aspose file tools*
The moose likes Beginning Java and the fly likes Creating subclass of abstract class at runtime Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Creating subclass of abstract class at runtime" Watch "Creating subclass of abstract class at runtime" New topic
Author

Creating subclass of abstract class at runtime

amar nath jha
Ranch Hand

Joined: Mar 09, 2006
Posts: 42
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

Joined: Jan 28, 2008
Posts: 5575

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

Joined: Jan 28, 2008
Posts: 5575

As per your subjectline
------------------------------
Creating subclass of abstract class at runtime
--------------------------------

i think below one helps,


Hope this helps
Bill Shirley
Ranch Hand

Joined: Nov 08, 2007
Posts: 457
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 ]

Bill Shirley - bshirley - frazerbilt.com
if (Posts < 30) you.read( JavaRanchFAQ);
amar nath jha
Ranch Hand

Joined: Mar 09, 2006
Posts: 42
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

Joined: Mar 09, 2006
Posts: 42
Hey I found one more link

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Creating subclass of abstract class at runtime