Results 1 to 2 of 2

Thread: Java reflection getting parameter types

  1. #1
    Join Date
    Sep 2010
    Posts
    5,762
    Mentioned
    136 Post(s)
    Quoted
    2739 Post(s)

    Default Java reflection getting parameter types

    I'm trying to get a parameter type how do I do that, I have this:

    java Code:
    import java.lang.reflect.InvocationTargetException;
    import java.lang.reflect.Method;
    import java.lang.reflect.Parameter;


    public class Hello {
       
        public Hello() {
        }
       
        public static void H(int j) {
            System.out.println("Hi");
        }
       
        public static int G() {
            System.out.println("H g i");
            return 6;
        }
        public static void main(String[] args) throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
            Hello g = new Hello();
            Method[] methods = g.getClass().getMethods();
            for(int i = 0;i < methods.length; i++) {
                Parameter[] a = methods[i].getParameters();
                Class <?> unknown = a[i].getType();
                System.out.println(unknown.getName());
            }  
        }

    }

  2. #2
    Join Date
    Mar 2012
    Location
    127.0.0.1
    Posts
    3,383
    Mentioned
    95 Post(s)
    Quoted
    717 Post(s)

    Default

    method.getParameterTypes()
    ???

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •