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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T17:53:28+00:00 2026-05-13T17:53:28+00:00

Most of the documentation regarding type erasure handling in Java assumes that the use

  • 0

Most of the documentation regarding type erasure handling in Java assumes that the use case is handling a type like SomeType<ParamType>.
I am trying to process method parameter for the following method:

public void setOtherReferenceRanges(List<ReferenceRange<T>> referenceRanges)

When the container class is instantiated with a type DvQuantity, this signature should become
public void setOtherReferenceRanges(List<ReferenceRange<DvQuanitity>> referenceRanges) in runtime.

Using reflection one can see that the List has an actualTypeArgument which is ReferenceRange<T>. Since reflection uses class information, I would not expect it to give me ReferenceRange<DvQuantity>.
However, when I created the class containing this method, I passed the DvQuantity type as T. So the type filling in T should be available to Java runtime, but I could not find a way of getting it. I end up with a TypeVariableImpl object accessed via reflection, which does not seem to contain any useful data.

Can you think of any ways to discover this information in runtime?

  • 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-13T17:53:28+00:00Added an answer on May 13, 2026 at 5:53 pm

    When you say

    when I created the class containing this method

    I guess you mean when you create an object of that type, for example:

    foo = new ContainerClass<DvQuantity>();
    

    In that case, because of erasure, there is no way to recover the type DvQuantity.

    However, if you create a class passing a type parameter to the superclass, like this

    class DvQuantityContainerClass extends ContainerClass<DvQuantity> {...}
    ...
    foo = new DvQuantityContainerClass();
    

    Or, shorter, an inline anonymous subclass (which looks almost like the first example but with a subtle but important difference):

    foo = new ContainerClass<DvQuantity>(){};
    

    Then you can recover the type parameter, because you recover the type parameter used to extend a superclass at runtime. Unfortunately, Java itself doesn’t provide an easy way to now get the type of the DvQuantityContainerClass.setOtherReferenceRanges method with the T filled in. For that, I’ve written gentyref, to do advanced reflection on generic types:

    Method m = DvQuantityContainerClass.class.getMethod("setOtherReferenceRanges", List.class);
    // this will return List<ReferenceRange<DvQuanity>>, like you are lookingn for
    return GenericTypeReflector.getExactParameterTypes(m, DvQuantityContainerClass.class)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm currently working with an XML Schema that has <xsd:annotation> / <xsd:documentation> on most
How do I add an extra check to the default Symfony login_check? Most documentation
The documentation for ref() mentions several possible return values. I understand most of them,
Most of us write conditionals like: if (resultIndex == 0) ...but occaisionally I come
I'm new to HTML. When I started reading documentation about lists, I've noticed that
Reading the documentation and going through the Apple sample codes (and most of the
Background Given that 'most' developers are Business application developers, the features of our favorite
Most projects have some sort of data that are essentially static between releases and
I was reading the documentation of std::sub_match<BidirectionalIterator> and saw that it publicly inherits from
Super easy question, that somehow I can't figure out by reading the documentation.I am

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.