Why Android View class has 'outValues style' getters for handful of properties? -


you can view properties height, alpha, id, matrix, drawingtime or elevation using standard getters (like getheight(), getalpha(), getid()...).

but then, have of view's properties (most of them point or rect return type) locationinwindow, globalvisiblerect, locationinscreen, drawingrect, drawingcache hidden under getters forcing create returning objects beforehand empty constructor, , pass objects getter parameter data being 'saved' them.

example of getter globalvisiblerect:

public final boolean getglobalvisiblerect(rect r) 

forces (kotlin):

val rect = rect() getglobalvisiblerect(rect) dosomestuffwithrect(rect) 

it's not consistent, nor debuggable in realtime expressions tab in android studio , it's cumbersome, really.

why done way? see of methods returning false boolean value if view not visible, know returned data invalid, shouldn't solved returning null value, if method knows produced unusable information? on other hand, getlocationonscreen returns void , has no additional parameters, can't understand why complicate stuff way.

why done way?

to encourage reuse of objects, such via object pool. creating zillion rect instances , having gc clean them inefficient, particularly on 2006-era devices. creating , collecting zillion rect instances fragments heap, still problem pre-android 8.0 devices, though android 5.0's changes helped somewhat.


Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -