Then don't use getters and setters... A lot of complaints people have about Java seem to be about the way in which they choose to write Java.
My somewhat unorthodox rules for writing Java:
1. Don't use private. No reason to restrict yourself or others, and do extra typing. Friendly is a perfectly good default.
2. Don't use reflection. Reflection is only useful for making frameworks. Frameworks don't reduce the complexity of the problem you're trying to solve. Don't use them.
3. Don't use getters/setters. Sometimes they make sense for updating a cached value, or using a different underlying representation, but in general it's unnecessary clutter. If you still want them (e.g., for code style reasons), just generate them.
4. Don't use other people's code (tongue-in-cheek). If you use third-party libraries, consider wrapping them in your own interfaces as needed. This makes it easy to change the implementation and perform tests. It's not much effort, since you'll rarely use more than a limited subset of the functionality offered by the library. If you need a large subset, then just use the library directly.
5. Use final. Immutability makes programs simpler, more efficient, and inherently thread-safe.
6. Consider writing bean classes as follows. It's simple, efficient, thread-safe, and has a clean syntax (item.name):
public class Item {
public final int id;
public final String name;
public Item(int id, String name) {
this.id = id;
this.name = name;
}
}
7. Use an IDE, refactor, find references, generate code. It's easy to changes names and styles later, so just focus on important things like performance and reliabiltiy.
8. Keep improving the way you write your code, don't listen to the crowd.
My somewhat unorthodox rules for writing Java:
1. Don't use private. No reason to restrict yourself or others, and do extra typing. Friendly is a perfectly good default.
2. Don't use reflection. Reflection is only useful for making frameworks. Frameworks don't reduce the complexity of the problem you're trying to solve. Don't use them.
3. Don't use getters/setters. Sometimes they make sense for updating a cached value, or using a different underlying representation, but in general it's unnecessary clutter. If you still want them (e.g., for code style reasons), just generate them.
4. Don't use other people's code (tongue-in-cheek). If you use third-party libraries, consider wrapping them in your own interfaces as needed. This makes it easy to change the implementation and perform tests. It's not much effort, since you'll rarely use more than a limited subset of the functionality offered by the library. If you need a large subset, then just use the library directly.
5. Use final. Immutability makes programs simpler, more efficient, and inherently thread-safe.
6. Consider writing bean classes as follows. It's simple, efficient, thread-safe, and has a clean syntax (item.name):
7. Use an IDE, refactor, find references, generate code. It's easy to changes names and styles later, so just focus on important things like performance and reliabiltiy.8. Keep improving the way you write your code, don't listen to the crowd.