Ho un ente che ha una proprietà enum:utilizzando enum in switch/case
// MyFile.java
public class MyFile {
private DownloadStatus downloadStatus;
// other properties, setters and getters
}
// DownloadStatus.java
public enum DownloadStatus {
NOT_DOWNLOADED(1),
DOWNLOAD_IN_PROGRESS(2),
DOWNLOADED(3);
private int value;
private DownloadStatus(int value) {
this.value = value;
}
public int getValue() {
return value;
}
}
Voglio salvare questa entità nel database e recuperarlo. Il problema è che io salvo il valore int nel database e ottengo un valore int! Non posso usare l'interruttore come di seguito:
MyFile file = new MyFile();
int downloadStatus = ...
switch(downloadStatus) {
case NOT_DOWNLOADED:
file.setDownloadStatus(NOT_DOWNLOADED);
break;
// ...
}
Cosa devo fare?
potrebbe essere il caso peggiore, ma solo la soluzione che posso vedere è usare un getter diverso estendendo la classe che restituisce valore come enum. –