假设您有一个名为Field的特定枚举:
public enum Field {
ALBUM,
DESCRIPTION
}
另一个名为:
public enum Operator {
CONTAINS,
EQUALS,
LESS_THAN,
GREATER_THAN
}
你有一个名为Music
的相应Java界面public interface Music {
String getAlbum();
String getDescription();
}
实现看起来像这样:
public class MusicImpl implements Music {
@Override
public String getYear() {
return Field.Year.toString();
}
@Override
public String getDescription() {
return Field.DESCRIPTION.toString();
}
@Override
public Object getField(Field field) {
Object myObject = field.getClass();
return myObject;
}
}
您如何使用此API实现以下两种方法?
public class MyApp {
@Override
public List<Music> searchMusic(String query) {
// What to put in this?
}
@Override
public List<Music> filterMusic(Field field, Operator op, String query) {
// What to put in?
}
}