ERLEDIGT
NEIN
NEIN
ANTWORTEN
1
1
ZUGRIFFE
653
653
EMPFEHLEN
-
Hi,
kurze Frage:
Kann man nicht public Methoden via Reflection auslesen? In der API steht das man mit getMethods() nur public Methoden bekäme.
Hier eine Beispielauslesemethode
Code :1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
public static void showMethods( Object o ) { Class c = o.getClass(); Method theMethods[] = c.getMethods(); String erg = ""; System.out.println("Es gibt "+theMethods.length+" soviele Methoden"); for ( int i = 0; i < theMethods.length; i++ ) { // Modifier int modifierString = theMethods[i].getModifiers(); System.out.print(Modifier.toString(modifierString) + " " ); erg = Modifier.toString(modifierString) + " "; // Rückgabewert String returnString = theMethods[i].getReturnType().getName(); System.out.print( returnString + " " ); // Methodenname String methodString = theMethods[i].getName(); System.out.print( methodString + "(" ); // Parameter Class parameterTypes[] = theMethods[i].getParameterTypes(); for ( int k = 0; k < parameterTypes.length; k ++ ) { System.out.print(parameterTypes[k].toString()); if ( k < (parameterTypes.length - 1) ){System.out.print( ", " );} } System.out.print( ")"); // Exceptions Class exceptions[] = theMethods[i].getExceptionTypes(); if ( exceptions.length > 0 ) { System.out.print(" throws "); for ( int k = 0; k < exceptions.length; k++ ) { System.out.print( exceptions[k].getName() ); if ( k < (exceptions.length - 1)) System.out.print(", "); } } System.out.println(); } }Geändert von Thomas Darimont (17.12.03 um 16:51 Uhr)
-
Sorry,
hat sich geklärt - hab den Wald vor lauter Bäumen nicht gesehen.
Wenns interressiert statt getMethods() einfach
getDeclaredMethods() nehmen.
cya Luxor
Ähnliche Themen
-
Reflection - Wie kann ich Werte zu einer List<> hinzufügen?
Von Jacky87 im Forum .NET WPF & SilverlightAntworten: 2Letzter Beitrag: 18.05.10, 18:24 -
Reflection - wie kann ich eine Methode benutzen
Von y0dA im Forum JavaAntworten: 3Letzter Beitrag: 21.01.08, 10:26 -
Via Java Reflection Methoden-Parameter-Bezeichnung ermitteln
Von DarthShader im Forum JavaAntworten: 2Letzter Beitrag: 31.12.07, 20:51 -
Private Attribute über Reflection auslesen
Von Thomas Darimont im Forum .NET Application und Service DesignAntworten: 8Letzter Beitrag: 19.07.06, 14:55 -
auf public Methoden zugreifen...
Von stephan r. im Forum .NET ArchivAntworten: 7Letzter Beitrag: 11.02.05, 11:37





Zitieren
Login





