0

I know this has been asked before but I am posting this question because I honestly dont know how this would work. The last site I have visited had the following info:

Class  aClass = ... //obtain Class object. See prev. section
Class[] interfaces = aClass.getInterfaces();

So assuming I had something like this:

public interface Speech{
    vocal doomething();
}

class english implements Speech{
    public int doSomething() {
        return 1;
    }

class german implements Speech{
    public int doSomething() {
        return 2;
    }
}

How would I store all classes dynamically in an array? Im asking because right now im forced to do the following:

static HashMap<String, Speech> map = new HashMap<>();

and set the maps manually:

 map.put("English", new English());
 map.put("German", new German());

But I would like to do something like this:

function void setSpeech(String language) {
    map.put(language, new x());
}

How is this possible? Can it be done with reflection? If so then how?

Asperger
  • 3,064
  • 8
  • 52
  • 100

0 Answers0