0

I've been trying to create a program that goes through a subfolder and adds all the .java files within to a list in the code, so I can access it later.

I can easily get all the file directories in a string list, but what i'm having trouble with is getting the program to add them in without the class needing to be defined.

Since i feel that's confusing here's an example:

In minecraft there are a ton of types of blocks. In my program, it would add a bunch of them to a list without needing to specifically reference that block like this:

list.add(new DirtBlock());

So is it possible to add a class to the program from inside the code?

I know it's possible in python because Crea did this kind of thing, but I haven't seen it done in java before.

  • 1
    Java does not use the `.java` files, for anything other than compiling them into `.class` files. It then uses the `.class` files in the run time. – christopher Feb 24 '14 at 16:43
  • Do you mean Dynamic Compilation and Execution in Java? Cause it exists. – Aman Agnihotri Feb 24 '14 at 16:43
  • possible duplicate of [how to create a dynamic class at runtime in Java](http://stackoverflow.com/questions/2980429/how-to-create-a-dynamic-class-at-runtime-in-java) – jgitter Feb 24 '14 at 16:43
  • Actually, I asked some people from school, and I was trying to use Reflection http://stackoverflow.com/questions/37628/what-is-reflection-and-why-is-it-useful – user3347488 Mar 15 '14 at 23:06

1 Answers1

0

Yes there is some possibility to manipulate java assembly. First I know Assis library. There is also very interesting article about that topic bytecode manipulation

RMachnik
  • 3,598
  • 1
  • 34
  • 51