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 9154031
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T12:21:58+00:00 2026-06-17T12:21:58+00:00

This is all in the context of JBox2D (in Java). The World class creates

  • 0

This is all in the context of JBox2D (in Java). The World class creates Body instances with a function. I’m trying to add a bit more stuff to Body for my application. Body is represented by ComplexClassWithLotsOfAPI in this question.

Here is the generalized question. I am trying to add a bit more functionality to a premade class by extending the class. I hope to do something like this:

class SomeMore extends ComplexClassWithLotsOfAPI{
    int myExtraInt;
    //A bit more API functions
}

So that I may do this:

SomeMore sm=new SomeMore();
sm.someOldAPI();
sm.butAlsoMyNewAPI();

The problem is that this ComplexClassWithLotsOfAPI is created by another class that I can’t modify (the World class in the original context), so I am not simply creating them on my own (otherwise this would work). Since I am stuck having to start with a ComplexClassWithLotsOfAPI, I have been searching for a way to construct a SubClass from a SuperClass, whereas there are many examples of casting a SuperClass to a Subclass (but this is not applicable here). Here is an example of the function that needs to be completed:

public SomeMore create(...){ 
    ComplexClassWithLotsOfAPI ccwlao=myWorld.create(...);
    SomeMore sm;
    //??
    return sm;
}

Alternative to Wrapping?
My original solution was to encase the ComplexClassWithLotsOfAPI into my own class. In order to construct my new class, I simply pass the old class into my new constructor and move on:

class SomeMore{
    public ComplexClassWithLotsOfAPI ccwloa;
    int myExtraInt;
    public SomeMore(ComplexClassWithLotsOfAPI nccwloa){
        ccwloa=nccwloa;
        myExtraInt=0;
    }
    //A bit more API functions
}
public SomeMore create(...){ 
    ComplexClassWithLotsOfAPI ccwlao=myWorld.create(...);
    SomeMore sm=new SomeMore(ccwlao);
    return sm;
    //OR more simply
    //return new SomeMore(myWorld.create(...));
}

But in order to access the old API, I need to do this:

SomeMore sm=new SomeMore();
sm.ccwloa.someOldAPI();
sm.butAlsoMyNewAPI();

I could just be a bit unreasonable, but this kind of functionality is tedious and adds just that much more complication to something that doesn’t need it. I mean, if someone wanted to add a tad more functionality, would they wrap my class into yet another class, and have 3 class heirarchies to go through to get old APIs? Also, it would feel just wasteful to wrap every single API in the old class into my new class (there’s a lot of them).

sm.someOldAPIButWrappedInMyClass(); //not desirable

I do not have access to the java files of ComplexClassWithLotsOfAPI, only the compiled class files. I can not simply force my modifications into the old class (and even if I could, I’d prefer not to anyway). I am relatively new to java, so perhaps this is not the best/proper way to do this, but I haven’t been able to find an alternative.

  • 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-17T12:21:58+00:00Added an answer on June 17, 2026 at 12:21 pm

    Eclipse can build you a delegate class that is a subclass of some class (i.e. Parent) and holds an instance of ‘Parent’ in a field (called the delegatee) and generates methods that override all the methods in ‘Parent’ with calls to the same method in the delegatee. You can then add your own methods.

    You do this from the context menu, Source option, generate delegate methods. You have to have the subclass and have it extend ‘Parent’ and have a field of type ‘Parent’ to let the code generator work.

    Here’s an example:

    /** Example class delegating to a contained variable */
    public class DelegatingComparator implements Comparator<String> {
        // Delegatee has to be present before letting Eclipse generate
        private Comparator<String> delegatee;
    
        /** My own method extends Comparator methods */
        public int compareToFoo(String o1) {
            return compare(o1, "foo");
        }
    
        /** Generated by Eclipse. Source > Generate getters and setters */
        public void setDelegatee(Comparator<String> delegatee) {
            this.delegatee = delegatee;
        }
    
        /** Generated by Eclipse. Source > Generate Delegate Methods */
        public int compare(String o1, String o2) {
            return delegatee.compare(o1, o2);
        }
    
        /** Generated by Eclipse. Source > Generate Delegate Methods */
        public boolean equals(Object obj) {
            return delegatee.equals(obj);
        }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is all in the context of a larger program, so Im going to
We all know to set canvas's context property like this: ctx.textBaseline = top; ctx.shadowColor
First of all, the context of this question is: Cannot install psycopg2 on OSX
I'm using this code for get all news: List<aspnet_News> allNews = context.aspnet_News.OrderByDescending(i => i.NewsId).ToList();
So, I'm making this context menus, which looks great in all major browsers, even
I have this markup: <div id=slider1> <div class=ui-slider ui-slider-horizontal ui-widget ui-widget-content ui-corner-all> <a style=left:
I'm trying to figure out why this works: >>> comments = Comment.objects.all() >>>[c.content_object for
I'm creating an OpenGL render context on Windows, using ChoosePixelFormat, SetPixelFormat, etc. This all
I have tried the following: $(shell ./libpng/configure) ./libpng/configure under this context all : build_jpeg
I'm trying to make a custom context menu. I'll eventually put in all the

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.