Hi Guys,
Its been one of those days can someone help me out with this.
I have 2 Stock Objects which I want to compare properties of at runtime. One instance is the cached instance, the other is a new stock instance which has just been delivered to my system, which may or may not equal the cached instance. See below where m is a method from the class Stock and stock is an instance of Stock
try {
// I want to compare these two objects, return type of m may vary
Object result = m.invoke(stock);
Object cacheResult = m.invoke(stockCache.get(ticker));
// The return type of m may vary but is known at runtime
Class returnType = m.getReturnType();
// I assume I need to cast before .equals() will work correctly
if(result.equals(cacheResult)) {
// Will this work or do I need to cast
}
}catch (Exception ex) {
}
EDIT: For those who have asked about why I am using reflection, I am using the reverse ajax framework DWR and I am trying to map a html id property to my object properties, allowing me to annotate my properties with their associated HTML id value. When pushing the object to the UI this method will allow me to only push properties that have changed and not the whole object.