Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7759115
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T13:32:44+00:00 2026-06-01T13:32:44+00:00

I have the capability to extend a class at compile time, but I need

  • 0

I have the capability to extend a class at compile time, but I need to be able to create an instance of this subclass at runtime using an instance of the superclass that was already instantiated.

This should be possible in theory because superclass constructors are already called before the subclass constructor.

I do not have access to the program sufficiently to change the instantiation to my subclass nor to interrupt the original instantiation.

Use Case: There is an existing array of instances of class X. My code is loaded in after. I need to override one of the methods of one of the instances X with my loaded subclass Y extends X. The parent program accesses the objects only through that array, so I want to replace that array element with my Y instance, but it needs to behave as if it were instantiated originally into that array. I cannot just enclose the superclass instance and forward calls, and there are difficult complications with reinstantiating the superclass.

I hope that is more clear.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T13:32:46+00:00Added an answer on June 1, 2026 at 1:32 pm

    To reiterate what you are trying to do..

    Within the JVM, there exists an instance of ClassA. You would like to dynamically modify the class heiarchy of ClassA, such that a new class exists called ClassB which derives from ClassA. Then you would like to instantiate an instance of ClassB but have it’s subclass implementation be that of the existing instance of ClassA. Something like a memory replacement.

    You might want to look into http://www.jboss.org/javassist . What you would need to do is replace the ClassLoader, then determine when ClassA is being loaded, then instantiated. You’d then need to construct ClassB and return that instead.

    Update

    After a little more research there is still the possibility you can do what you want. IDE’s like Eclipse support HotSwap’ing method implementations while debugging. They use the Instrumentation API.

    http://zeroturnaround.com/blog/reloading_java_classes_401_hotswap_jrebel/

    You can replace method bodies but not add or remove methods themselves. So while you won’t be able to change the type to your new type, you can completely replace the method implementation with your new implementation.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've been reading this but I was just wondering, does Solr have the capability
interfaces provide a useful abstraction capability. One can have a class Foo implement some
I am adding a voice memo capability using AVAudioRecorder and I need to know
I'm writing delphi app which should have capability of loading plugins. I'm using JvPluginManager
I'm saving NumPy arrays using numpy.save function. I want other developers to have capability
Have a look at this picture alt text http://www.abbeylegal.com/downloads/2009-04-01/web%20part%20top%20line.jpg Does anyone know what css
have not tested on windows. but in ubuntu when u disconnect from the network,
I'm researching how to best extend a C++ application with scripting capability, and I
Does Visual Studio have a capability, or is there a VS plug-in, that will
My silverlight application will have print capability, the printing module is created in separated

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.