There's nothing built-in to the language, but you could always use Project Lombok's annotation set to generate getters and setters for you at compile-time.
In particular, @Data
is quite powerful - it generates your getter, setter, and a toString()
method.
Here's an example:
import lombok.Data;
@Data
public class Node<T extends Comparable<T>> {
private final T data;
private Node<T> left = null;
private Node<T> right = null;
public Node(final T theData) {
data = theData;
}
public void add(final Node<T> theNode) {
if(data.compareTo(theNode.getData()) <= 0) {
// goes to the left
left = theNode;
} else {
// goes to the right
right = theNode;
}
}
}
You may have to install a plugin for your IDE to recognize that this is being generated at compile-time, but this takes care of all of your setter and getter boilerplate code.