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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T22:14:31+00:00 2026-05-16T22:14:31+00:00

Okay the question title may not have made sense… mostly because I don’t know

  • 0

Okay the question title may not have made sense… mostly because I don’t know how to explain it.

Here is what I have:

class SomeClass 
{
    private Class paramType;
    private SomeInterface<?> someObject;
}

public interface SomeInterface<T>
{
    public void foo(T in);
}

The variable someObject might be assigned to like this:

someObject = new SomeInterface<Integer> { ... }

I want to be able to invoke the generic method on someObject like this:

someObject.foo(paramType.cast(someVariable));

The issue is that someObject is of type SomeInterface. Now, is there some way I could get someObjects‘s REAL type so that I could invoke the method correctly?

I know I could use reflection and do something like .getMethod("foo", paramType); But, I don’t like the fact that “foo” has to be hardcoded by the client. If you can find a more robust way of calling that method, I’d be open to this as well.

Any ideas? Sorry if this isn’t quite making sense… feel free to edit if you think you can explain it better :).

EDIT: Some functional designs, as it might seem insane that I’m going this route :).

Basically, I’m making a framework that will allow a client to hook into some event. An example of this would be:

SomeClass.addHandler(Integer.class, new SomeInterface<Integer> {
    public void foo(Integer in)
    {
        // do something
    }});

So, I’m basically trying to write the event trigger function. The advantage of going this route is that the client doesn’t have to worry about casting anything, and has type safety (I can restrict the addHandler parameter to be SomeInterface<bar> for example).

The “invoker” just has to get the data into the appropriate object (easy) and call SomeInterface’s method (hard) with that object.

I’ve almost given up and may just resort to making the client have to cast, but I’m so close!

  • 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-16T22:14:32+00:00Added an answer on May 16, 2026 at 10:14 pm

    You need to parameterize the addHandler() method as well. Then the cast will work.

    public <T> void addHandler(Class<T> paramType, SomeInterface<T> someObject) {
        someObject.foo(paramType.cast(someVariable));
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Okay, this may be a dumb question, but I've not been able to find
Okay, the title is not saying too much, sorry. Essentially it's an Architecture Question
Okay that's probably not the best title, I know why we need browser resets:
I had trouble coming up with a title for this question because I'm not
Okay, I know this question have been asked plenty of times already, but I
Okay this is not a question of how to get all uniques or How
Okay. Complex Title for a simple(?) problem. I have something like this going on
Okay. Complex Title for a simple(?) problem. I have something like this going on
Okay, I'm not trying to do anything super complex, I have searched, and searched,
Okay this is a fairly broad question. This is my first App and I'm

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.