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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T04:25:04+00:00 2026-06-06T04:25:04+00:00

I am trying to use a string to call a method? Suppose I have

  • 0

I am trying to use a string to call a method?

Suppose I have a class called Kyle which has 3 methods:

public void Test();
public void Ronaldo();
public void MakeThis();

And I have a string with the name of the method which I need to call:

String text = "Test()";

Now I need to call the method whose name is inside of this string:

Kyle k = new Kyle();

k.text;?

  • 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-06T04:25:06+00:00Added an answer on June 6, 2026 at 4:25 am

    You’ll need to use java Reflection to do this.

    See: Class.getMethod()

    Using your specific example:

    String text = "Test";
    Kyle k = new Kyle();
    Class clas = k.getClass();
    
    // you'll need to handle exceptions from these methods, or throw them:
    Method method = clas.getMethod(text, null);
    method.invoke(k, null);
    

    That’s without the exception handling required for getMethod() and Method.invoke(), and only covers the case of calling methods that take no arguments.

    See also:

    • Method doc
    • Class doc
    • This reflection article with examples
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to use this UrlHelper extension method: public static string ToPublicUrl(this UrlHelper
I'm trying to call overloaded method in code like this: public abstract class BaseClass<T>
I have a class Exporter which has a generic method which accepts an IEnumerable<T>
So I'm trying to make a combobox use a string that has other strings
Hi I am trying to use C# reflection to call a method that is
I am trying to use XmlRpc.NET to call a method with following signature (the
I have a WCF service which I am trying to use to generate an
I am trying to use jQuery to directly call ASP.NET AJAX page methods. I'm
I'm trying to use std::string instead of char* whenever possible, but I worry I
I'm trying to use the following: String dbquery = Select * From stops where

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.