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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T13:55:13+00:00 2026-05-16T13:55:13+00:00

First off let me say I am maintaining someone else’s poorly designed code so

  • 0

First off let me say I am maintaining someone else’s poorly designed code so I am limited in how much I can change it.

Now what is happening is that they have created a series of methods that are invoked by reflection. One of those methods takes a Map as one of its arguments. At runtime this Map is implemented with a Hashtable.

Here’s the problem – I get a NoSuchMethodException because it is looking for a method with Hashtable as an argument even though a Hashtable implements the Map interface. What is confusing me is that if I don’t use reflection (a major design change in this case) and passed a Hashtable it would invoke the method with the Map parameter – so why doesn’t it work the same way when I use reflection?

Given that I pretty much have to stick with reflection is there any way to get the method with the Map argument to get invoked when I pass it a class that implements that interface?

If you want I can mock some code up to demonstrate…

  • 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-16T13:55:13+00:00Added an answer on May 16, 2026 at 1:55 pm

    If you are using getMethod(String name, Class[] parameterTypes) from java.lang.Class, you need to specify parameter types as expressed in the method signature of the interface (static type), not the type of the object at run-time (dynamic type).

    So, for methodXyz(Map map), instead of:

    Method m = cl.getMethod("methodXyz", new Class[]{argument.getClass()});
    

    do this:

    Method m = cl.getMethod("methodXyz", new Class[]{Map.class});
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

First off, let me say I am a new to SAX and Java. I
I have a C# button, let's say 'ON/OFF': I want to change 'OFF', when
First off let me just say, i dont want anyone to post solutions because
First off let me just say I'm very new to coding so there are
First off, let me say that I am familiar with content_for . It's not
First off, let me say that this is not homework (I am an A-Level
First off let me say I'm a beginner at programming. So far I've done
First off, please let me say I'm pretty new to CSS. Still lots to
Ok, let me first off say I'm assuming this is related to caching. but
First off let me say I am running on SQL Server 2005 so I

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.