Android Performance - 'Avoid Internal Getters/Setters'

前端 未结 7 760
情歌与酒
情歌与酒 2020-12-08 07:45

Just read this on the dev site:

Avoid Internal Getters/Setters

In native languages like C++ it\'s common practice to use getters (e.g. i = get

7条回答
  •  独厮守ぢ
    2020-12-08 08:12

    Keep in mind that those performance considerations are relevant only if the member in question is accessed thousands of times per second.

    A good example where direct access may be a good idea is the scenegraph of a game (libgdx)

    public abstract class Actor {
        public Group parent;
        public final String name;
        public boolean touchable = true;
    
        public float x;
        public float y;
        public float width;
        public float height;
        public float originX;
        public float originY;
        public float scaleX = 1;
        public float scaleY = 1;
        public float rotation;
        public final Color color = new Color(1, 1, 1, 1);
    

提交回复
热议问题