On 9/3/2015 11:04 PM, Shawn Heisey wrote:
> It sounds like your code is trying to assign the result of the
> createClient method to an object of type SystemDefaultHttpClient.  This
> is a derivative type of CloseableHttpClient.  This would work if the
> derivation were the other direction.
> 
> The compiler is saying that you cannot make this assignment.  I tried to
> put these code lines into a SolrJ program:
> 
> SystemDefaultHttpClient sc;
> sc = HttpClientUtil.createClient(someParams);

I thought up an imperfect comparison to help understand why this is a
problem.

Think about "SystemDefaultHttpClient" as Infiniti, a brand of car.
Think about "CloseableHttpClient" (the type returned by createClient) as
Nissan.  The Infiniti brand is owned and built by Nissan.

Taking this idea further, imagine that "sc" is a parking spot that
expects to hold a car made by Infiniti.  Trying to park a Nissan there
isn't going to work, because the parking spot owner is very picky about
exactly what gets to park there.

The reverse works just fine ... an Infiniti can take a spot made for a
Nissan, and the parking spot owner will be very happy, because an
Infiniti *is* a Nissan, only fancier.

Similarly, a SystemDefaultHttpClient is a CloseableHttpClient, but a
CloseableHttpClient is not a SystemDefaultHttpClient.

Thanks,
Shawn

Reply via email to