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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T21:26:28+00:00 2026-05-23T21:26:28+00:00

I am trying to learn the difference between getGenericParameterTypes and getParameterTypes methods. I know

  • 0

I am trying to learn the difference between getGenericParameterTypes and getParameterTypes methods. I know that one returns Class[] and the other Type[]. But what is ther real difference?

Considering methods:

public void method1(T arg1)
public void method2(String arg2)

What would I get when invoking each of the get methods over each of the example methods?

  • 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-23T21:26:29+00:00Added an answer on May 23, 2026 at 9:26 pm

    I can’t exactly tell you what you would get, but one difference is that for method 2 you can tell the parameter type is Class<String> whereas for method 1 you’d just know there’s a parameter named T, but you don’t know the exact type except the class where T is declared would have been subclassed with a concrete class for T.

    Example:

    class Foo<T> {
       public void method1( T arg1 ) { ... }
    }
    
    class Bar extends Foo<Baz> { ... }
    
    Foo<?> foo = new Foo<Baz>();
    Bar bar = new Bar();
    

    For foo you’d not be able to get the type of T at runtime (you’d not know it’s Baz) nor at compile time. For bar you’d be able to get the type for T since it is already known at compile time.

    Another difference when looking at the code:

    Calling getGenericParameterTypes() on method 1 should return the T type, calling it for method 2 should return Class<String>. However, if you call getTypeParameters() you’d get the T type for method 1 but a zero-length array for method 2.

    Edit: since getParameterTypes() was meant instead of getTypeParameters() here’s the difference I can see from the code:

    For method 2 there would be no difference, since if no Generics are used in the signature, getGenericParameterTypes() actually calls getParameterTypes(). For method 1 getGenericParameterTypes() would return a ParameterizedType that states the parameter has name T whereas getParameterTypes() would return the required base class of the type, e.g. Class<Object> for <T> or Class<Number> for <T extends Number>.

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

Sidebar

Related Questions

I know how that question looks, but I'm quite serious. I am trying to
What I am trying to learn is what is the difference between the window,
Trying to learn MVP pattern with C#... Does anyone know of any particularly good
I am trying to learn all the new goodies that come with C# 4.0.
I'm trying to compare between the different template engines for PHP. The 2 that
I'm trying to learn how to use the Control.Parallel module, but I think I
I am writing a program in C. I am trying to learn the difference
I am trying to learn how to specify class constructors in Java. I am
I'm trying to learn Objective C & Cocoa, but I just can't manage to
Trying to learn a bit of CSS and I want a horizontal navbar and

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.