There is a class in this form. Ie to write Foo or Bar with the indication of import will not work, just like that.
Class foo = Class.forName("com.secret.Foo"); Class bar = Class.forName("com.secret.Bar"); There is a method in the Foo class called make . He needs to pass an array of Bar classes. How to implement this?
If you could use these classes
Bar bar1 = new Bar(1); Bar bar2 = new Bar(2); Bar[] bars = {bar1, bar2}; Foo.make(bars); What about reflection?
UPD
Tried to do so
ArrayList<Object> ar = new ArrayList<>(); ar.add(bar1); ar.add(bar2); Class foo = Class.forName("com.secret.Foo"); for(Method m : foo.getMethods()){ if(m.getName().equals("make")) { m.invoke(foo, new Object[]{ar.toArray()}); } } But this way I get an error
java.lang.IllegalArgumentException: method com.secret.Foo.make argument 1 has type com.secret.Bar[], got java.lang.Object[]