0

What I'm trying to do is have a folder with classes in it. Then be able to loop through those classes, and trigger a method named "String getVariables(Object player, String line)".

But I have no clue where to start...

Rao Ehsan
  • 778
  • 8
  • 15
Bimmr
  • 33
  • 6
  • Are you expecting many of the classes in that folder to have versions of that method? If so, do they share a common interface or abstract superclass where that method is declared? – Dawood ibn Kareem Apr 11 '14 at 04:32
  • Why is it "getVariables" when it returns a String? Why does every class have a getVariables that takes an "Object" player and a "String" line (is there a relationship there)? Do you have instances of these classes? If not, do they have default constructors? – Elliott Frisch Apr 11 '14 at 04:32

1 Answers1

1

I will not provide you with code but i will send you in a direction which will resolve your issue.

1: Locate the files(Which are Classes), store them in an array if you want.

2: Create a ClassLoader/URLClassLoader and set the url to the path of the file{http://docs.oracle.com/javase/7/docs/api/java/net/URLClassLoader.html}

3: Depending on what the access of the method is(Static/Instance) you will either need to create an instance of that class or just invoke the static method, this can be acomplished with reflection{http://docs.oracle.com/javase/tutorial/reflect/}

This question has been asked a few times or questions similar to yours.

Method to dynamically load java class files

Java: How to load Class stored as byte[] into the JVM?

How do I invoke a Java method when given the method name as a string?

I hope this helps you!

Community
  • 1
  • 1
Francis Malloch
  • 1,074
  • 9
  • 20