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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T09:16:47+00:00 2026-05-16T09:16:47+00:00

I wish to a check if a method exists in an interface based on

  • 0

I wish to a check if a method exists in an interface based on its signatures.

The signature that the method should have is:

Collection<Foo> methodName(Spam arg0, Eggs arg1, ...)

I can find the methods via Class.getMethods()
then find the name, parameters and return type respectively with method.getName(), method.getParameterTypes() and method.getReturnType().

But what do I compare the return type to in order to ensure that only methods that return Collection<Foo> are chosen, and not other collections?

method.getReturnType().equals(Collection.class) 

Since the above will be true for all methods that return a collection, not just for those that return a Foo Collection.

  • 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-16T09:16:47+00:00Added an answer on May 16, 2026 at 9:16 am

    There is a method named public Type getGenericReturnType() which can return (if it’s the case) a ParameterizedType.

    A ParameterizedType can give you more informations on a generic type such as Collection<Foo>.

    In particular with the getActualTypeArguments() method you can get the actual type for each parameter.

    Here, ParameterizedType represents Collection and getActualTypeArguments() represents an array containing Foo

    You can try this to list the parameters of your generic type :

    Type returnType = method.getGenericReturnType();
    if (returnType instanceof ParameterizedType) {
        ParameterizedType type = (ParameterizedType) returnType;
        Type[] typeArguments = type.getActualTypeArguments();
        for (Type typeArgument : typeArguments) {
            Class typeArgClass = (Class) typeArgument;
            System.out.println("typeArgClass = " + typeArgClass);
        }
    }
    

    Sources :
    http://tutorials.jenkov.com/

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

Sidebar

Related Questions

I have the following method that I wish to verify behaviour on. public void
I wish to make sure that my data has a constraint the following check
On my main window I have a DataGridView that I wish to display my
I wish to add a PMD check to ensure that a class does not
I wish my method to wait about 500 ms and then check if some
I have this provided function that I want to use: boolean check(Comparable<Object> obj1, Comparable<Object>
SO I wish to check to see if the item in my array [clientDataArray
I wish to know what are the methods exist to check the Health of
I have 2 dictionaries, and I want to check if a key is in
Here's a strange question for you guys, I have a nice sorted list that

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.