如何在 Android Studio 中自动生成 getter 和 setter [英] How to automatically generate getters and setters in Android Studio

查看:95
本文介绍了如何在 Android Studio 中自动生成 getter 和 setter的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Android Studio 中是否有自动生成给定类中的 getter 和 setter 的快捷方式?

Is there a shortcut in Android Studio for automatically generating the getters and setters in a given class?

推荐答案

Using Alt+ Insert for Windows or Command+ N for Mac 在编辑器中,您可以轻松地为类的任何字段生成 getter 和 setter 方法.这与使用菜单栏的效果相同 -> Code -> Generate...

Using Alt+ Insert for Windows or Command+ N for Mac in the editor, you may easily generate getter and setter methods for any fields of your class. This has the same effect as using the Menu Bar -> Code -> Generate...

然后使用 shift 或 control 按钮,选择需要添加 getter 和 setter 的所有变量

and then using shift or control button, select all the variables you need to add getters and setters

这篇关于如何在 Android Studio 中自动生成 getter 和 setter的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆