Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6126299
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T16:21:20+00:00 2026-05-23T16:21:20+00:00

I use to the advice given by Joshua Bloch’s Effective Java, Item 52: Refer

  • 0

I use to the advice given by Joshua Bloch’s Effective Java, Item 52: Refer to objects by their interfaces.

However, in most of the sample code comes with Android, I realize the following code is quite common.

private ArrayList<Integer> mPhotos = new ArrayList<Integer>();

I understand this is due to performance optimization purpose, as the following code will be slower.

private List<Integer> mPhotos = new ArrayList<Integer>();

However, is such optimization technique still valid? As if I read from
http://developer.android.com/guide/practices/design/performance.html

On devices without a JIT, it is true that invoking methods via a variable with an exact type rather than an interface is slightly more efficient. (So, for example, it was cheaper to invoke methods on a HashMap map than a Map map, even though in both cases the map was a HashMap.) It was not the case that this was 2x slower; the actual difference was more like 6% slower. Furthermore, the JIT makes the two effectively indistinguishable.

Do we need to assume our devices are without JIT, and refer objects without interfaces? Or, shall we just adopt to Joshua Bloch’s advice?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T16:21:21+00:00Added an answer on May 23, 2026 at 4:21 pm

    As of Android 2.2, the Dalvik VM (that runs the Dalvik bytecode that is the result of your Java source code) has a Just-in-time compiler (JIT).

    I don’t know if this particular optimization is part of the JIT or not, but it should be testable on actual devices.

    If you target pre-2.2 devices and those 6% overhead in invocation (which is not to be confused with an overal 6% slowdown of your application!) has a serious effect on your application, then that optimization might be worthwhile.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've read through the web after being given advice to use the jbjs SDK
Do you have any advice/rules on selecting a multiplier to use in a (multiplicative)
I would like some advice on the best approach to use in the following
I'm looking for some advice on whether or not I should use a separate
I need some advice on what kind of pattern(s) I should use for pushing/pulling
In another Stack Overflow question Leon Timmermans asserted: I would advice you not to use
With halfdans advice , I was successfully able to use goinstall github.com/hoisie/web.go without any
I currently use this piece of code to reduce a given text to a
Given the image below, what algorithm might I use to detect whether regions one
I am developing a small, internal-use only web application. Given its simple nature and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.