简体   繁体   English

Eclipse快捷方式以调用POJO的设置者

[英]eclipse shortcut to call setters of a POJO

Suppose I have a POJO with 10 fields with setters and getters. 假设我有一个带有10个带有setter和getter的字段的POJO。 If I want to instantiate that class, I have to manually type those setters method. 如果要实例化该类,则必须手动键入这些setters方法。

For Eg 例如

Employee emp = new Employee();
emp.setId(XXX);
emp.setName(XXX);
emp.setCompany(XXX);

and so on. 等等。

Is there a eclipse shortcut to call setters of class? 是否有蚀快捷方式来调用类的设置方法?

Considering you have Employee class, 考虑到您有Employee类,

Employee constructor would be like, 员工构造函数会像

public Employee(int empId, String empName, String empDept, String address, int pinCode){

//Costructor Body eg. this.empId = empId etc. 

}

Instantiation of Employee with constructor would be like, 用构造函数实例化Employee就像

Employee e = new Employee(1,"abc","def","ghi",123);

If you want to instantiate that class without remembering order of variables Then all you have to do is type 如果您想实例化该类而不记住变量的顺序,那么您要做的就是键入

Employee e = new E Now press Ctrl + Space Eclipse will prompt you with all the constructors available for that class for instantiation of Employee object. Employee e = new E现在按Ctrl + Space Eclipse将提示您提供该类可用的所有构造函数以实例化Employee对象。 With this, You don't need to remember the order in which those variables are given in to constructor as parameters. 这样,您就无需记住将这些变量作为参数提供给构造函数的顺序。

Hope this helps ! 希望这可以帮助 !

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM