This week's book giveaway is in the Agile and other Processes forum. We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line! See this thread for details.
I am using a POJO ( a very simple class: some variables + getters and setters) to store info of bikes. For example:
Therefore, each bike is represented by one POJO.
I would like to know if it is possible to create a method which takes the class as parameter. For example:
So I can just pass one parameter (the class) instead of having to execute all the getters in that class to obtain all the variables and then call the method with thousand parameters.
Mnau Lubi wrote:So I can just pass one parameter (the class) instead of having to execute all the getters in that class to obtain all the variables and then call the method with thousand parameters.
Do you mean that you want to set the fields of all existing instances of a certain class to certain values? There is no way in Java to find all existing instances of a class, if you only know the class. Java doesn't keep track of all the instances of a class; you have to do that yourself. So if that's what you mean, then that's not possible.
If you have all your Track objects in a collection, for example a List, you could ofcourse pass that List to your method:
Or... are you maybe confusing the terms "class" and "object", and do you simply mean that you want to pass a Track object to your method: