invoquer_une_methode_par_son_nom
Différences
Ci-dessous, les différences entre deux révisions de la page.
Dernière révisionLes deux révisions suivantes | |||
invoquer_une_methode_par_son_nom [2020/04/25 02:05] – créée Mushussu | invoquer_une_methode_par_son_nom [2020/04/25 02:05] – Mushussu | ||
---|---|---|---|
Ligne 1: | Ligne 1: | ||
====== Invoquer une méthode par son nom======= | ====== Invoquer une méthode par son nom======= | ||
+ | Cet exemple permet d' | ||
+ | <code java> | ||
+ | import java.lang.reflect.InvocationTargetException; | ||
+ | import java.lang.reflect.Method; | ||
+ | |||
+ | void setup() { | ||
+ | noLoop(); | ||
+ | } | ||
+ | |||
+ | void draw() { | ||
+ | invoquer(" | ||
+ | } | ||
+ | |||
+ | void invoquer(String s, String argument) { | ||
+ | try { | ||
+ | Method m = this.getClass().getMethod(s, | ||
+ | m.invoke(this, | ||
+ | } | ||
+ | catch (NoSuchMethodException x) { | ||
+ | x.printStackTrace(); | ||
+ | } | ||
+ | catch (InvocationTargetException x) { | ||
+ | x.printStackTrace(); | ||
+ | } | ||
+ | catch (IllegalAccessException x) { | ||
+ | x.printStackTrace(); | ||
+ | } | ||
+ | } | ||
+ | |||
+ | void maMethode(String s) { | ||
+ | println(" | ||
+ | } | ||
+ | </ |
invoquer_une_methode_par_son_nom.txt · Dernière modification : 2020/04/25 02:06 de Mushussu