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

The Archive Base Latest Questions

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

Suppose you have a generic interface and an implementation: public interface MyInterface<T> { void

  • 0

Suppose you have a generic interface and an implementation:

public interface MyInterface<T> {

  void foo(T param);
}

public class MyImplementation<T> implements MyInterface<T> {

  void foo(T param) {

  }
}

These two types are framework types I provide. In the next step I want allow users to extend that interface as well as redeclare foo(T param) to maybe equip it with further annotations.

public interface MyExtendedInterface extends MyInterface<Bar> {

  @Override
  void foo(Bar param);

  // Further declared methods
}

I create an AOP proxy for the extended interface and intercept especially the calls to furtherly declared methods. As foo(…) is now redeclared in MyExtendedInterface I cannot execute it by simply invoking MethodInvocation.proceed() as the instance of MyImplementation only implements MyInterface.foo(…) and not MyExtendedInterface.foo(…).

So is there a way to get access to the method that declared a method initially? Regarding this example is there a way to find out that foo(Bar param) was declared in MyInterface originally and get access to the accoriding Method instance?

I already tried to scan base class methods to match by name and parameter types but that doesn’t work out as generics pop in and MyImplementation.getMethod("foo", Bar.class) obviously throws a NoSuchMethodException. I already know that MyExtendedInterface types MyInterface to Bar. So If I could create some kind of “typed view” on MyImplementation my math algorithm could work out actually.

Additional info:

I create the proxy for the MyExtendedInterface as follows:

ProxyFactory factory = new ProxyFactory();
factory.setTarget(new MyImplementation());
factory.setInterfaces(new Class[] { MyExtendedInterface.class });
factory.addInterceptor(new MyInterceptor(MyExtendedInterface.class));

The interceptor pretty much scans the methods and executes JPA queries for all methods declared in MyExtendedInterface but routes all method invocations of methods declared in MyInterface to the proxy target. This works as long as methods from MyInterface are not redeclared as the target then doesn’t implement it anymore.

public class MyInterceptor implements MethodInterceptor {

  public Object invoke(final MethodInvocation invocation)
            throws Throwable {

    // handling of query methods
    // else

    invocation.proceed();
    // ^^ works if not redeclared but not if
  }
}

So what I would like to do instead of invocation.proceed() is detect the method that originally declared the one being invoked and invoke that on the target manually.

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

    Okay, here’s the solution I came up with: As I know the base class and it generics structure (what T means in this case) as well as MyExtendedInterface types MyInterface to Bar I can scan the base implementation for possible matches as follows (pseudocode):

    for all methods {
    
       skip those with non matching name and parameters length;
    
       for all generic parametertypes {
    
         if typename = T then concrete type has to be Bar
         ...
       }
    }
    

    I don’t need a generic solution in this case so that seems to work.

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

Sidebar

Ask A Question

Stats

  • Questions 542k
  • Answers 542k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I copied your code into a new project could not… May 17, 2026 at 3:15 am
  • Editorial Team
    Editorial Team added an answer I believe that memoizing a function allows you to locally… May 17, 2026 at 3:15 am
  • Editorial Team
    Editorial Team added an answer You could add an instance method to the User model… May 17, 2026 at 3:15 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

Suppose I have an interface for a service: public interface IFooService { void DoSomething();
Suppose I'm using an interface with a generic type parameter interface Foo<T> { T
Suppose you have an interface like this: public interface IDoSomething<out T> { T DoSomething(object
Suppose I have the following models: class User(models.Model): pass class A(models.Model): user = models.ForeignKey(User)
Suppose I have a simple EventArgs subclass: class MyArgs : EventArgs { } Consider
The following code: public interface ISomeData { IEnumerable<string> Data { get; } } public
What I basically wish to do is design a generic interface that, when implemented,
Suppose you have a text file like: my_setting = ON some_method = METHOD_A verbosity
Suppose I have a family of types which support a given member function, like
Suppose i have this sql statement and I have executed a sql command to

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.