Actually, shouldn't reflection be fixed so that you can invoke any method of a non exported class, if the method overrides one that is accessible to the class calling invoke... Not sure it makes sense...
W dniu 12.01.2018 o 20:25, mandy chung pisze: > > > On 1/12/18 10:26 AM, jeffrey kutcher wrote: >> m = o.getClass().getMethod("add", new Class[] { >> Object.class, }); >> o = m.invoke(o, new Object[] { button1, }); > > o.getClass().getMethod(...) is an anti-pattern for finding a public > method. Object.getClass() returns the implementation class while you > want to invoke a public method `javafx.collections.ObservableList::add` > in this case. In this case, the declaring class of the method is known > and so one way to fix it is to use the specific Class: > > Class<?> observableListClass = javafx.collections.ObservableList.class; > m = observableListClass.getMethod("add",new Class[] { Object.class, }); > o = m.invoke(o,new Object[] { button1, }); > > Mandy > > > >