Can I collapse those two "getFields" methods into one using generics (the second method is intended to package private access) or should I rename the second one into something ugly like "getFieldPackagePrivate"?
public interface IField {
}
class Field implements IField { // package private class
}
public class IForm {
public List<IField> getFields();
}
public class Form {
private List<Field> fields;
public List<IField> getFields() {
return this.fields;
}
List<Field> getFields() { // package visible
return this.fields;
}
}
the basic usage would be like this
// by interfece - from client code
IForm form;
List<IField> list = form.getFields();
// by class - from other classes in the same package
Form form2;
List<Field> list2 = forms2.getFields();
The idea is to have a clean, save interface for an outside world and a convenient access (without downcasts) from package visible implementation clacces. My Field Class has a few methods that I don't want do be seen by a client but need to invoke from other classes in the same packege (like for example setLabel etc.)