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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T04:31:16+00:00 2026-06-04T04:31:16+00:00

I am setting visibility on and off for many elements. Now I want to

  • 0

I am setting visibility on and off for many elements. Now I want to create a method that will receive an Object, assuming that every class top parent is Object, that would be good enough? If that’s what I should do, how should I cast them?
And I want to check if the received objects contains a setVisibility method and if it does perform some actions.

Should I just try and run the method and catch an exception? sounds dumb.
What should I do then?

  • 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-04T04:31:17+00:00Added an answer on June 4, 2026 at 4:31 am

    See the first example here, http://java.sun.com/developer/technicalArticles/ALT/Reflection/

       import java.lang.reflect.*;
    
       public class DumpMethods {
          public static void main(String args[])
          {
             try {
                Class c = Class.forName(args[0]);
                Method m[] = c.getDeclaredMethods();
                for (int i = 0; i < m.length; i++)
                System.out.println(m[i].toString());
             }
             catch (Throwable e) {
                System.err.println(e);
             }
          }
       }
    

    You basically get the class variable for object you are looking at, call the getDeclaredMethods() to get a array of method names. You can then check to see if the method name exists on the class.

    Further down the page there is an example for invoking the method as well.

       import java.lang.reflect.*;
    
       public class method2 {
          public int add(int a, int b)
          {
             return a + b;
          }
    
          public static void main(String args[])
          {
             try {
               Class cls = Class.forName("method2");
               Class partypes[] = new Class[2];
                partypes[0] = Integer.TYPE;
                partypes[1] = Integer.TYPE;
                Method meth = cls.getMethod(
                  "add", partypes);
                method2 methobj = new method2();
                Object arglist[] = new Object[2];
                arglist[0] = new Integer(37);
                arglist[1] = new Integer(47);
                Object retobj 
                  = meth.invoke(methobj, arglist);
                Integer retval = (Integer)retobj;
                System.out.println(retval.intValue());
             }
             catch (Throwable e) {
                System.err.println(e);
             }
          }
       }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to swap two LinearLayouts by setting their visibility properties to VISIBLE
Setting up the sandboxes for all these option is not feasible right now. So
I currently have a webview that displays a current site. However, it cuts off
Been tinkering with some code regarding setting the visibility of a drop down based
I'm having trouble with setting the visibility of a tab when a file is
In a function handling a registration form I want to set the visibility of
I'm printing a document by creating a System.Diagnostics.Process object and then setting the StartInfo
Using VS2008, Silverlight 4. I have created an AttachedProperty, RequiresRole, that I'm setting in
Does anyone know of any harm in hiding flash elements that collide with an
I'm trying to make a little game that will first show the player a

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.