• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Frank Carver
  • Henry Wong
  • Ron McLeod
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Himai Minh

Creating subclass of abstract class at runtime

 
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 5575
Eclipse IDE Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As per your subjectline
------------------------------
Creating subclass of abstract class at runtime
--------------------------------

i think below one helps,


Hope this helps
 
Ranch Hand
Posts: 457
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey I found one more link

 
I don't like that guy. The tiny ad agrees with me.
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic