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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T05:57:15+00:00 2026-05-11T05:57:15+00:00

Given 2 interfaces: public interface BaseInterface<T> { } public interface ExtendedInterface<T0, T1> extends BaseInterface<T0>

  • 0

Given 2 interfaces:

public interface BaseInterface<T> { } public interface ExtendedInterface<T0, T1> extends BaseInterface<T0> {} 

and a concrete class:

public class MyClass implements ExtendedInterface<String, Object> { } 

How do I find out the type parameter passed to the BaseInterface interface?

(I can retrieve the ExtendedInterface type parameters by calling something like

MyClass.class.getGenericInterfaces()[0].getActualTypeArguments() 

but I can’t spot an easy way to recurse into any base generic interfaces and get anything meaningful back).

  • 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. 2026-05-11T05:57:16+00:00Added an answer on May 11, 2026 at 5:57 am

    This problem is not easy to fully solve in general. For example, you also have to take type parameters of the containing class into account if it’s an inner class,…

    Because reflection over generic types is so hard using just what Java itself provides, I wrote a library that does the hard work: gentyref. See http://code.google.com/p/gentyref/ For your example, using gentyref, you can do:

    Type myType = MyClass.class;  // get the parameterized type, recursively resolving type parameters Type baseType = GenericTypeReflector.getExactSuperType(myType, BaseInterface.class);  if (baseType instanceof Class<?>) {     // raw class, type parameters not known     // ... } else {     ParameterizedType pBaseType = (ParameterizedType)baseType;     assert pBaseType.getRawType() == BaseInterface.class; // always true     Type typeParameterForBaseInterface = pBaseType.getActualTypeArguments()[0];     System.out.println(typeParameterForBaseInterface); } 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Given this magical interface: public interface IHat<out TRabbit> { TRabbit Take(); } And this
What is the simplest way of testing if an object implements a given interface
Given this: Interface IBase {string X {get;set;}} Interface ISuper {string Y {get;set;}} class Base
Given the following interfaces/classes: public interface IRequest<TResponse> { } public interface IHandler<TRequest, TResponse> where
Given the following code: public interface IExample { ... } public abstract class BaseExample:
Given the following interfaces: interface IFoo { void Foo(); } interface IBar : IFoo
Given the following two interfaces (these are small examples, not my actual implementation): public
Given the following public class Service<T> : IService<T> { Repository<T> _repository = new Repository<T>();
We need to get all the instances of objects that implement a given interface
Given two interface references obtained from different sources. Is there a programmatic way 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.