I have this class constructor AppData(Map params, Operations operation)
where Operations is
public enum Operations
{
create,update,delete,view,compare
}
How can I instantiate AppData with parameters constructor?
for the map parameter its fine i get that from servlet, (req.getParameterMap())
but the main problem for me is knowing the operation type, which also comes from the map parameter, So in order to do this AppData data=new AppData(req.getParameterMap(),op); what shall I assign to op or what shall an op type be?
Note: I can get the String create , update … from req.getParameterMap() by using iterator and Map.Entry object.getKey() and Value
Assuming you’re starting with a string (e.g.,
"update"), you can useEnum.valueOf. YourOperationsenum will inherit a form of that, so:…or use the one from
Enum, though you’d really only have to do this if you don’t have direct, compile-time access toOperations. I think you do have compile-time access, so use the above. But for completeness: