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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T23:41:38+00:00 2026-06-14T23:41:38+00:00

I have: interface I<T> {} and: interface I1 extends I<Clazz1> {} I have also

  • 0

I have:

interface I<T> {}

and:

interface I1 extends I<Clazz1> {}

I have also I2, I3 and so on which extend I<Clazz2>, I<Clazz3> etc.

I don’t know about Clazz1 in runtime. How could I get this information?

I tried:

subInterface1.getInterfaces()[0].getTypeParameters()[0]

but in only knows about T, not about Clazz1.

  • 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-14T23:41:40+00:00Added an answer on June 14, 2026 at 11:41 pm

    When you do

    subInterface1.getInterfaces()[0].getTypeParameters()[0]
    

    you are getting the first formal type parameter of the Class object representing the interface I, which is indeed the variable T. Instead you need to use

    subInterface1.getGenericInterfaces()[0]
    

    to get the Type object representing the particular instantiation of I that has been extended by I1. This will be an instance of ParameterizedType, so you can cast to that and then use getRawType() and getActualTypeArguments() to extract the raw type I and the actual type parameter value Clazz1 respectively. Note that the return type of getActualTypeArguments() is Type[] rather than Class[] because the actual arguments might not be concrete classes, they could be variables or wildcards (or indeed other parameterized types, in a case such as List<List<String>>).

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

Sidebar

Related Questions

I have an interface parametrized on a type which extends a parametrized type, and
As we know, interfaces can extend interface in the Java. I have a question
I have my OrganizationRequestContext interface, which works great: @Service(OrganizationDAO.class) public interface OrganizationRequestContext extends RequestContext
the code I have is: interfacebase<T> interfaceA extends interface<A> ---> interfaceAImpl implements interfaceA interfaceB
If use MongoRepository, You can have following code: @Repository public interface UserRepo extends MongoRepository<User,
I have the following interface: interface MySortedCollection<T extends Comparable<T>> { boolean isElement(T t); void
Say I have this code - public interface ParentInterface1 { public List<? extends ChildInterface1>
Let's say I have several POJOs which all extend a common supertype, BaseObject .
I want to test which interfaces a class/interface is implementing. So I have a
I have interface: public interface CartService extends RemoteService{ <T extends ActionResponse> T execute(Action<T> action);

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.