I am writing an Android project that needs to use the Apache HttpClient from version 4.1 of the project. I am including this in the libs folder of the project as a jar file. My question is how does the class loader know to use the version 4 class instead of the platform supplied version 3, as they both have the same package name and the same import statement?
I encountered a problem when using a GSON library in the past which clashed with the one included by HTC see here and wonder how these situations differ (maybe because gson is using reflection?)? Any info would be great thanks.
The classloader looks in his classes first and after that the parent classloader is asked.
Thr problem may be that the parent classloader has a patched class that works in android, while the version you are providing is not. This may lead to problems.
Long story short:
Classloader are stored in a tree and when the class is not found the parent classloader is asked.
(custom classloaders may do something different!)