How to make a java reflection program output look better? -


I have created a Java Reflection program similar to Java, everything works fine but I was wondering whether the output is displayed Better way to do What do I mean that I would like to take out Java method String which is in dispute of each method. Here's my method. Compare public static void (string)

  Public static zero performance methods (strings) throws ClassNotFoundException {class < & Gt; C1 = Orbit. Force (S); Method [] con = c1.getDeclaredMethods (); For (method c: con) println (c); }   

This is my output

  public boolean java.lang.String.equals (java.lang.Object) public java.lang.String java Lang .tring.toString () public int java.lang.String.hashCode () public int java.lang.String.compareto (java.lang.Object) public int java.lang.String.compareTo (java.lang.String) public Int java.lang.String.indexOf (java.lang.String, int) static int java.lang.String.indexOf (four [], int, int, java.lang.String, int) Fixed int java.lang. String.indexOf (four [], int, int, char [], int, int, int)    

Here's a quick and dirty solution:

 for  (method method: clazz.getDeclaredMethods ()) {stringbilder output = new stringbilder (); Output.append (Modifier.toString (method.getModifiers ())); If (method.getModifiers ()! = 0) {output.append (""); } Output.append (method.getReturnType (). GetSimpleName ()) .append ("") .append (method.getName ()) .append (for "("); for param parameter (method.getParameters ()) {Output.append (modifier.toString (param.getModifiers ()); Boolean for firstParam = true; (Parameter: param.getParameters ()) {if (! FirstParam) {output.append (","); } FirstParam = False; Output.Append (UltimateGet Type). GetSimpleName ());} Output.Append (The Ultimate .get type). GetSimpleName ());} output.append (")"); Println (production); }   

for example output public static final string foo (int x, string y) :

  public static final string Instead of declaring declaration foo (int, string) output, there is a return type in output, but you can easily change it for more customized output including exceptions, Look at the code and customize it according to your needs.   

Comments

Popular posts from this blog

java - ImportError: No module named py4j.java_gateway -

python - Receiving "KeyError" after decoding json result from url -

.net - Creating a new Queue Manager and Queue in Websphere MQ (using C#) -