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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T04:25:57+00:00 2026-05-28T04:25:57+00:00

I’m working on my first real project with Java. I’m beginning to get comfortable

  • 0

I’m working on my first real project with Java. I’m beginning to get comfortable with the language, although I have more experience with dynamic languages.

I have a class that behave similar to the following:

class Single
{
    public void doActionA() {}
    public void doActionB() {}
    public void doActionC() {}
}

And then I have a SingleList class that acts as a collection of these classes (specifically, it’s for a 2D Sprite library, and the “actions” are all sorts of transformations: rotate, shear, scale, etc). I want to be able to do the following:

class SingleList
{
    public void doActionA() {
        for (Single s : _innerList) {
            s.doActionA();
        }
    }

    ... etc ...
}

Is there any way to simply defer a method (or a known list of methods) to each member of the inner list? Any way without having to specifically list each method, then loop through each inner member and apply it manually?

To make things a bit harder, the methods are of varying arity, but are all of return type “void”.

  • 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-05-28T04:25:58+00:00Added an answer on May 28, 2026 at 4:25 am

    Unfortunately Java does not readily support class creation at runtime, which is what you need: the SingleList needs to be automatically updated with the necessary stub methods to match the Single class.

    I can think of the following approaches to this issue:

    1. Use Java reflection:

      • Pros:
        • It’s readily available in the Java language and you can easily find documentation and examples.
      • Cons:
        • The SingleList class would not be compatible with the Single class interface any more.
        • The Java compiler and any IDEs are typically unable to help with methods called via reflection – errors that would be caught by the compiler are typically transformed into runtime exceptions.
        • Depending of your use case, you might also see a noticeable performance degradation.
    2. Use a build system along with some sort of source code generator to automatically create the SingleList.java file.

      • Pros:
        • Once you set it up you will not have to deal with it any more.
      • Cons:
        • Setting this up has a degree of difficulty.
        • You would have to separately ensure that the SingleList class loaded in any JVM – or your IDE, for that matter – actually matches the loaded Single class.
    3. Tackle this issue manually – creating an interface (e.g. SingleInterface) or a base abstract class for use by both classes should help, since any decent IDE will point out unimplemented methods. Proper class architecture would minimize the duplicated code and your IDE might be able to help with generating the boilerplate parts.

      • Pros:
        • There is no setup curve to get over.
        • Your IDE will always see the right set of classes.
        • The class architecture is usually improved afterwards.
      • Cons:
        • Everything is manual.
    4. Use a bytecode generation library such as Javassist or BCEL to dynamically generate/modify the SingleList class on-the-fly.

      • Pros:
        • This method is extremely powerful and can save a lot of time in the long term.
      • Cons:
        • Using bytecode generation libraries is typically not trivial and not for the faint-hearted.
        • Depending on how you write your code, you may also have issues with your IDE and its handling of the dynamic classes.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have thousands of HTML files to process using Groovy/Java and I need to
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I have a jquery bug and I've been looking for hours now, I can't
this is what i have right now Drawing an RSS feed into the php,
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString

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.