I touched Java and Eclipse for the first time in a long time. When I used to use Eclipse a long time ago, I felt that it was difficult to use and I didn't like it, but I thought that it would be quite easy to use if I remember the shortcuts and functions. For the time being, this time I will write about how to automatically generate a constructor.
For example, suppose you have a class like this:
public class Dog {
String name;
void bark() {
System.out.println(name + ":「Bowwow.」");
}
}
It is troublesome to manually enter the constructor here, so select Source → Generate Constructor using Fields ... from the menu bar, select the field you want to set, and click generate to automatically generate the constructor.
public class Dog {
String name;
void bark() {
System.out.println(name + ":「Bowwow.」");
}
public Dog(String name) {
super();
this.name = name;
}
}
This will save you time.
Recommended Posts