0
如果我有@Autowired
道類:通@Autowired元素作爲函數的參數 - 春
@Service
public class MyClass implements MyInterface
{
@Autowired
private MyDao myDao;
//...
private Status findStatus(final MyStatus status)
{
return status.findStatus(myDao);
}
}
而且我想在枚舉使用此道是這樣的:
public enum MyStatus implements Serializable
{
NEW("")
{
public Status findStatus(final myDao myDao)
{
return myDao.findByType(AnotherStatus.STATUS_NEW);
}
}
//...
}
這是個好練習這樣做?或者我應該嘗試@Autowired
myDao
在enum
再次(但很可能我會得到一個NullPointerException
)?我認爲這有點奇怪 - 通過@Autowired
元素作爲函數參數,但我可能是錯的。
我不明白你爲什麼要在枚舉裏面找到findStatus方法。枚舉類型是一種特殊的數據類型,它使一個變量成爲一組預定義的常量 –