当前位置:网站首页>set方法和get方法
set方法和get方法
2022-04-22 06:20:00 【Vi---Rum】
手写set方法和get方法
public class Person01 {
/** * 昵称 */
private String nickname;
/** * 性别 1代表男性 0代表女性 */
private int gender;
/** * 年龄 */
private int age = 18;
public void setNickname(String name) {
nickname = name;
}
public String getNickname() {
return nickname;
}
public void setGender(int sex) {
gender = sex;
}
public int getGender() {
return gender;
}
public void setAge(int nianling) {
age = nianling;
}
public int getAge() {
return age;
}
}
使用IDEA快捷键创建set方法和get方法
alt+ins如下

public class Person02 {
/** * 昵称 */
private String nickname;
/** * 性别 1代表男性 0代表女性 */
private int gender;
/** * 年龄 */
private int age = 18;
public void setNickname(String nickname) {
nickname = nickname;
}
public String getNickname() {
return nickname;
}
public void setGender(int gender) {
gender = gender;
}
public int getGender() {
return gender;
}
public void setAge(int age) {
age = age;
}
public int getAge() {
return age;
}
}
lombok注解自动生成set方法和get方法
@Setter
@Getter
public class Person06 {
/** * 昵称 */
private String nickname;
/** * 性别 1代表男性 0代表女性 */
private int gender;
/** * 年龄 */
private int age = 18;
}
* 性别 1代表男性 0代表女性
*/
private int gender;
/** * 年龄 */
private int age = 18;
}
版权声明
本文为[Vi---Rum]所创,转载请带上原文链接,感谢
https://blog.csdn.net/weixin_54371657/article/details/124327723
边栏推荐
- F. Find 3-friendly integers (2021 Niuke summer multi school training camp 1)
- APC(一)
- Like fuzzy query of Android room database
- 843 · Digital Flip
- 案例案例案例
- L2-001 emergency rescue (extension of shortest Dijkstra - number of shortest paths & maximum weight of paths)
- Leetcode - 2 - (parenthesis generation, longest palindrome string, ring linked list, reverse linked list, nodes in pairwise exchange linked list)
- 使用使用使用
- A. Weird flecks, but OK (Computational Geometry & three-dimensional minimum circle coverage) (the first game of 2021 Training Alliance warm-up training competition)
- APC(四)
猜你喜欢

Redis的设计与实现(5):主从复制策略和优化

Tree + detailed explanation of binary tree + Top-k problem

Redis的设计与实现(4):什么是Redis的事件驱动程序

E. Figure skiing (string sorting / check-in) (Game 5 of 2021 training League warm-up training competition)

363 · rainwater connection

调用门

Redis的设计与实现(3):持久化策略RDB、AOF

页属性

Minimum circle coverage (basis of computational geometry)

Change DP (ah ah ah)
随机推荐
Kotlin collaboration flow, stateflow, shareflow
Bom 浏览器对象模型
2019.1.2 idea usage tutorial
Educational Codeforces Round 125 (Rated for Div. 2)
Leetcode - 4 - (longest substring without repeated characters, candy distribution, binary tree traversal)
D. Determine the Photo Position (简单找子串)(2021牛客暑期多校训练营1)
VAD 虚拟内存
APC(三)
并发编程的艺术(3):深入理解Synchronized的原理
pip一直更新失败?多数是网络问题!
363 · rainwater connection
101012分页
Detailed explanation of linked list exercises
Redis的设计与实现(5):主从复制策略和优化
Leetcode - 6 - (string multiplication, next larger element < Ⅰ Ⅱ Ⅲ >, K sets of inverted linked list)
The art of concurrent programming (11): introduction to tool classes in JUC
ES6模块化与Promise
Detailed overview of this keyword
Yapi的安装与配置(转载)
Addition, deletion and search of sequence table (find)