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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T00:09:19+00:00 2026-06-10T00:09:19+00:00

I found i have problems when reflecting on a method with generic type paremeter,

  • 0

I found i have problems when reflecting on a method with generic type paremeter, but the same code works fine with method without generic type paremeter! Here’s my code :

public class Test {

    public static void method1(Integer i) {
    }

    public static void method2(List<Integer> i) {
    }

    public static void main(String[] args) throws Exception {

        Integer i = 5;
        List<Integer> iList = new ArrayList<Integer>();
        Method method1 = Test.class.getDeclaredMethod("method1", i.getClass());
        method1.invoke(Test.class, i);
        System.err.println("-------- method 1 ok -----------");
        Method method2 = Test.class.getDeclaredMethod("method2", iList.getClass());
        method2.invoke(Test.class, iList);
        System.err.println("-------- method 2 ok -----------");
    }

}

And the output:

-------- method 1 ok -----------
Exception in thread "main" java.lang.NoSuchMethodException: 
Test.method2(java.util.ArrayList)
    at java.lang.Class.getDeclaredMethod(Class.java:1954)
    at Test.main(Test.java:24)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:601)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)

Is there anything magic with generic type paremeter ??

  • 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-10T00:09:20+00:00Added an answer on June 10, 2026 at 12:09 am

    ArrayList is too specific, you’ve only defined method2 as taking a List (as you generally should).

    Try with List.class

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

Sidebar

Related Questions

I have found similar problems on the web, but none of the posted solutions
I have a generic method that works for most of my custom types. Today
Hi i have problem with this code, i found it on the internet and
i have a problem using the Catch Clipboard Events code found on this link
I have a peculiar problem here. I want to extract some generic types, which
Problem: I have a generic super class with type T at GWT client side
I have found other examples of people having this problem but have had no
I have found that I have no problem using require to load something like
I'am currently working on GWTs Activity-Place implementation. Now I have found problem with the
i have problem with libhid . i found that there 2 way 4 accessing

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.