0

Its actual implementation is,

public void getSize(Point outSize) {
    synchronized (this) {
        updateDisplayInfoLocked();
        mDisplayInfo.getAppMetrics(mTempMetrics, mDisplayAdjustments);
        outSize.x = mTempMetrics.widthPixels;
        outSize.y = mTempMetrics.heightPixels;
    }
}

and also the documentation didn't mention this particular design.

Could this be because of synchronization? How effective would this be if it is returned instead? Just curious.

Also, why Point is used instead of Dimensions as Dimensions seems to be meaningful in this context. My apologies and please ignore if this question is too dumb.

mrtpk
  • 1,398
  • 4
  • 18
  • 38
rehman_00001
  • 1,299
  • 1
  • 15
  • 28
  • Probably because the guy who developed this part though it would be better – J j Sep 03 '16 at 15:16
  • 1
    "Could this be because of synchronization?" -- probably not. Usually, this pattern is to encourage object reuse, to avoid creating objects unnecessarily. This is particularly important when rendering the UI, where you want to avoid object allocation during `onDraw()` processing. Here, the caller can perhaps use a previously-allocated `Point` rather than `getSize()` always instantiating a new one. – CommonsWare Sep 03 '16 at 15:19
  • Thanks @CommonsWare. thats useful.! – rehman_00001 Sep 03 '16 at 16:04

1 Answers1

0

Realized that this design is used to encourage object-reuse just as in comments

rehman_00001
  • 1,299
  • 1
  • 15
  • 28