Thanks & Regards<br />Mallik Avula<br />SCJP1.4
Bill Shirley - bshirley - frazerbilt.com
if (Posts < 30) you.read( JavaRanchFAQ);
There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
"I'm not back." - Bill Harding, Twister
Ulf Dittmer wrote:The benefit is that returning an interface makes it possible to change the implementation later on. E.g., you might decide after a while that you'd much rather use a LinkedList instead of an ArrayList. If the return type is "ArrayList", you're out of luck - all code that depends on it must be recompiled (and possibly rewritten if it makes use of ArrayList features that are not part of List). Had you declared the return type to be List, you could simply return a LinkedList instead.
Most of the time it is sufficient to know that the type will be a List (or Map), without the need to use other features of the implementing classes.
OCPJP 6.0-81% | Preparing for OCWCD
http://www.certpal.com/blogs/cert-articles | http://sites.google.com/site/mostlyjava/scwcd |
Life is full of choices. Sometimes you make the good ones, and sometimes you have to kill all the witnesses.
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime. |