How to use the return value of a getter ,using reflection?

mygearis

New Member
Given class Round: \[code\]public class Round { private int roundNumber; private Door door1; private Door door2; public Round(int _roundNumber) { this.roundNumber = _roundNumber; } public void setRoundNumber(int _number) { this.roundNumber = _number; this.door1 = null; this.door2 = null; } public int getRoundNumber() { return this.roundNumber; }...\[/code\]and code in Main: \[code\]Round[] gameRounds; // manipulations on gameRounds , assume that we put some data into array gameRounds ......Object ret = null;for (int i = 0; i < gameRounds.length; i++){ Method roundFunction = Round.class.getMethod("getRoundNumber", new Class[] {}); ret = roundFunction.invoke(gameRounds); // need to put something here }\[/code\]I'm trying to retrieve the field \[code\]roundNumber\[/code\] with reflection , but the return value is Object type , how can I use its value , i.e. how can I convert it to \[code\]int roundNumber\[/code\] ? I need to write it into a new XML file ... Thanks
 
Back
Top