Since "VIOLIN.." is defined in the conf file and which might change in future, what can I write during the @Override of toString() ?
or can I avoid this @Override and still get 'VIOLIN' printed using Spring ?
Also, you didn't post all the code. How does "using…" printout. Where is that code?
The only other way besides overriding toString is to cast your Instrument to the actual type to get to the String instrument variable value. But that would remove you from coding to an interface which is a best practice to always code to an interface. So for me the only option you have and what should be done is overriding toString. Look at Object classes implementation of toString and you will see why you got your value.
I just added System.out.println("using " + getInstrument()); to the original System.out.println(getInstrument()); to make it more meaningful. Sorry for missing it out over here..
The only other way besides overriding toString is to cast your Instrument to the actual type to get to the String instrument variable value.
You mean to say just like the other variable song which I written?
I thought so and that's why made it bit different to see what would happen..
Besides, I also changed few things like adding setters/getter and and trying out different things in xml file , but couldn't overcome that problem.
Will try out the overriding method and let you know.
The main point I am saying here, at this point. Is that your issue is a plain Java issue, that you would have using these classes without Spring. Spring isn't causing the Instrument's toString method printing the object reference.