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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T07:33:51+00:00 2026-06-04T07:33:51+00:00

This is exceedingly bad OO, but I am not trying to put this in

  • 0

This is exceedingly bad OO, but I am not trying to put this in any kind of code that will be used by anyone but the coders themselves — it can never be called except for testing by coders.

Here is the problem I am facing: I have a series of classes that are defined externally. I cannot modify them in any way (except of course I could subclass or call them). They have a variety of names but they do not extend any superclasses (except Object), or implement any interfaces. However what I know about each of them is that they have a method called ‘call’.

For testing, I am trying to write code that will call any one of these classes’ call methods. But, of course, I cannot just say Object.call() because call is not defined for every Object.

Essentially, this will work:

MyClassOne classOne = new MyClassOne();
MyClassOneInput classOneInput = new MyclassOneInput();

classOne.call(classOneInput);

But this will not:

Object clazz = getClassFromElsewhere();
Object clazzInput = getClassInputFromElsewhere();

clazz.call(clazzInput).

Obviously, since Java is a strongly typed language.

BUT, for the sake of 10x faster testing for every person working on this system, can I get around that somehow and somehow use the ‘call’ method for any Class and any ClassInput? I have no problem if it generates an exception or breaks entirely if the wrong classes are passed.

Please help me violate Object Orientation.

  • 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-04T07:33:52+00:00Added an answer on June 4, 2026 at 7:33 am

    You can use reflection to do this.
    Check out the reflection API

    Here is a simple example:

    MyClassOne classOne = new MyClassOne();
    MyClassOneInput classOneInput = new MyClassOneInput();
    Method m = classOne.getClass().getMethod("call", MyClassOneInput.class);
    m.invoke(classOne, classOneInput);
    

    Note: you can use getDeclaredMethod to get any method, including private and protected ones but you’ll need to call “m.setAccessible(true)” on them if they are private/protected.

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

Sidebar

Related Questions

this is my code that I write it but I want to use LINQ
I've heard that it is a bad idea to do something like this. But
I have implemented some code that will automatically set a UIScrollView's ContentOffset when the
I feel this should be exceedingly obvious, but so far I've failed to find
It would be exceedingly handy if I could do this: var MyObject = function(param1,
This somehow simple task is not so simple. I can get the number of
This should be simple, but the answer is eluding me. If I've got a
This is probably a stupid question, but how much of a security risk is
This question has been answered. The problem was that myEventMoveTrainManaul() was being called from
I'm doing some performance testing of my app and noticed that it takes exceedingly

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.