Dealing with or casting an object returned from method.invoke() when using reflection
Using Java, I have a method which I'm calling with method.invoke that returns a string.
Method.invoke returns an object though which can't be cast to String.
How am I supposed to use the Object as a string??

In the docs on reflection it shows the following: 

    Object o = m.invoke(t, new Locale(args[1], args[2], args[3]));
    out.format("%s() returned %b%n", mname, (Boolean) o);

But my code does this and I get an exception: java.lang.Class cannot be cast to java.lang.String

					Object message = method.invoke(this); // expect a string
					
					if (message == null) {
						// no messeage
					} else {
						logger.debug("Calling listAnswers: got an answer: "
								+ message);

						// create an answer object from the reflected
						Answer answer = new Answer();
						answer.setText((String)message);//cast as string
						answerList.add(answer);
            }
Dealing with or casting an object returned from method.invoke() when using reflection
===

Using Java, I have a method which I'm calling with method.invoke that returns a string.
Method.invoke returns an object though which can't be cast to String.
How am I supposed to use the Object as a string??

In the docs on reflection it shows the following: 

    Object o = m.invoke(t, new Locale(args[1], args[2], args[3]));
    out.format("%s() returned %b%n", mname, (Boolean) o);

But my code does this and I get an exception: java.lang.Class cannot be cast to java.lang.String

					Object message = method.invoke(this); // expect a string
					
					if (message == null) {
						// no messeage
					} else {
						logger.debug("Calling listAnswers: got an answer: "
								+ message);

						// create an answer object from the reflected
						Answer answer = new Answer();
						answer.setText((String)message);//cast as string
						answerList.add(answer);
            }