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

  • Home
  • SEARCH
  • 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 7713329
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T01:50:55+00:00 2026-06-01T01:50:55+00:00

First suppose that I have an abstract class, let’s call it AbstractClass. Suppose public

  • 0

First suppose that I have an abstract class, let’s call it AbstractClass. Suppose

public abstract AbstractClass {
    public abstract void F();
}

Suppose that I have a class, let’s call it ClassA. ClassA extends AbstractClass. ClassA is saved in a folder. (It has to be loaded onto the classpath.) Now suppose that I am writing a new class within the program,

ClassB

and I want ClassB to be able to reference ClassA. Something along the lines of

public class ClassB extends AbstractClass {

    ClassA A = new ClassA();

    public void F() {
         A.F();
    }

}

Now, I have had no trouble using a class loader to get classA and use it dynamically. I have also had no problem writing a class like ClassA dynamically based on user input, compiling it within the program (using ecj.jar), and then loading it and calling methods from it.

I cannot figure out though how to reference a dynamically loaded class in a class that I am now writing and compiling dynamically. I don’t know how to write the import, etc. Loading classA and putting

import classA;

into the classB.java file does not do the trick.

This is my first question on StackOverflow (long time reader), so go easy on me. Thanks in advance.

—

Context: A program that uses probability distributions entered by the user. I have an abstract class AbstractDistribution which has abstract methods for the distribution’s CDF, PDF, inverse CDF, etc. So far this has worked well, dynamically writing compiling and loading distributions that extend AbstractDistribution, getting newInstance() of them and using them like any other class. However, if I have written and dynamically loaded a distribution Dist1, I want to be able to write a Dist2 that can call (for example), the PDF of Dist1.

  • 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-01T01:50:57+00:00Added an answer on June 1, 2026 at 1:50 am

    Don’t make B refer to A directly – make B refer to AbstractClass and take a reference to an instance in its constructor:

    public class ClassB extends AbstractClass {
    
        private final AbstractClass other;
    
        public ClassB(AbstractClass other) {
            this.other = other;
        }
    
        public void F() {
             other.F();
        }    
    }
    

    At this point you need to work out how you’re going to get hold of a reference to the other instance of AbstractClass (whether it’s a ClassA or something else) but it does get rid of the direct dependency.

    I’m sure there will be more exact details to work out, but if you can break the direct dependency like this, it should make the dynamic compilation aspect less of a problem.

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

Sidebar

Related Questions

Suppose that I have two classes, first a class without any properties, fields or
Suppose that I have a unsigned char*, let's call it: some_data unsigned char* some_data;
Suppose I have two columns in a table that represents a graph, the first
Suppose that I have a tree to traverse using a Depth First Search, and
I have code that suppose to find the first child (div) of a div
Let's suppose that I have a list of elements, and I want to select
I have an sql statement that is supposed to return 2 rows. the first
Suppose I want to implement a reasonably efficient 'keyword recognition algorithm', that is first
Suppose I have two XML files. First XML File: <?xml version=1.0?> <AccessRequest xml:lang=en-US> <AccessLicenseNumber>Your_License</AccessLicenseNumber>
Suppose I have two applications written in C#. The first is a third party

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.