-2

I might have been mis-understood, I want to create objects and specify which class the object is by using a string.

1 Answers1

5

Yes, you can use reflection for that.

To get a class, use

// if your class is in package com.foo and is named Bar
Class<?> klass = Class.forName("com.foo.Bar"); 

Read the tutorial for more details.

Guillaume Polet
  • 47,259
  • 4
  • 83
  • 117