For performance reasons. If you're using the interface reference, the interface needs to be converted to the right underlying type (in the developer guide on android.com from a general Map to HashMap, so basically it's a similar to doing ((HashMap)myMap1).anyMethod(...)).
It may be ok, if you use this once in your code, but it can get really bad if you do it in a do/for/foreach-loop, as evertime you'd call the method, it would to do the work above. However, sometimes you have to use the interface, if it's part of an API and you don't know in advance what kind of implementation the user would use, so you're forced to stick with the generic version. What it says (and that's what you can read in the guide which you obviously did ^^) is: If you know, that you will only be using HashMap in your function/application/activity/whatever, then there is no need to use generic Map interface, as it needs less CPU cylces = less CPU performance = faster code = longer battery life. This is important in embedded devices development, but not so important if you're developing for a Desktop PC with fast CPUs and no batteries at all. On Apr 3, 10:04 am, OT <s9027...@gmail.com> wrote: > Hi all, > > I don't known why "Calling through an interface reference > can take 2x longer than a virtual method call through a concrete > reference"? Could someone help to explain it, thank you very much. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Android Beginners" group. To post to this group, send email to android-beginners@googlegroups.com To unsubscribe from this group, send email to android-beginners-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-beginners?hl=en -~----------~----~----~----~------~----~------~--~---