Eclipse生成get,set方法,无参构造方法和有参构造方法

源码:

public class frist {
    
    
	String name;
	int age;
}
  • Alt+shift+S+R 生成setxxx()和getXXX()方法。
/**
	 * @return the name
	 */
	public String getName() {
    
    
		return name;
	}
	/**
	 * @param name the name to set
	 */
	public void setName(String name) {
    
    
		this.name = name;
	}
	/**
	 * @return the age
	 */
	public int getAge() {
    
    
		return age;
	}
	/**
	 * @param age the age to set
	 */
	public void setAge(int age) {
    
    
		this.age = age;
	}
  • Alt+shift+S+C 生成无参构造方法。
public frist() {
    
    
		super();
		// TODO Auto-generated constructor stub
	}
  • Alt+shift+S+O 生成有参构造方法。
public frist(String name, int age) {
    
    
		super();
		this.name = name;
		this.age = age;
	}
 
  • Alt+shift+S+S 重写toString()方法。
@Override
	public String toString() {
    
    
		return "frist [name=" + name + ", age=" + age + "]";
	}
	 

猜你喜欢

转载自blog.csdn.net/weixin_44182157/article/details/114983118