Hi, I have 2 classes, Quote and Value. In Quote class, I have an variable for type Value. In both classes , I have implemented toString() method.
Now I am calling the toString() method using below code.
I was expecting the values in both Quote and Value classes readable. But the toString() method from Value class is not getting invoked. The code is below. Could you please help why it is not invoking.
The type of the value variable is not what you expect! It is not your webservice.Value. It is com.fasterxml.jackson.annotation.JsonFormat.Value. That's why toString in the webservice.Value is never called - these values have never been part of the Quote.
Imported type always shadows types in the same package, see JLS, 6.4.1. Relevant section:
A single-static-import declaration d in a compilation unit c of package p that imports a type named n shadows, throughout c, the declarations of:
* any top level type (§7.6) named n declared in another compilation unit (§7.3) of p;
In your example solution is simple: just remove an offending import. If it is not possible (both classes are needed), you have to use fully-qualified names (i.e. full type name with its package) for all but one types with the same simple name (and you could import only that required one).
Today's lesson is that you can't wear a jetpack AND a cape. I should have read this tiny ad: