Java give a possible list for a parameter -


I want to create a parameter with multiple possibilities, in order to be more precise, I have 0,1,2 and 3 I would like to see different levels of alerts like When you write it, then you have only 4 possibilities.

Example: setFoobar (1, "yo");

Consider using it for:

  public enum severity {DEBUG, INFO, WARN, ERROR}  

[IMAGINE] Imagine, you have a way of logging a message with a different need. This enum indicates that in your method, you can do something like this again:

  switch (seriousness) {case DEBUG: // break the undiscovered; Case information: System.out.println (message); break; Case Warning: Case Error: System.err.println (Message); break; }  

... or just compare something:

  if (seriousness == seriousness. WARN || seriousness == seriousness. ERROR) {system .err.println (message); }  

In addition, a enum is like a normal class , which means that you can add state (e.g. In Variable) and methods, for example, you can directly move the given argument directly to enum :

  public enum severity {DEBUG ("some low -Last logging output "), information (" informative output "), warning (" a warning "), error (" a serious error "); Private string description; Personal severity (string description) {this.description = description; } Public Zero Output (String Message) {Switch (This) {Case DEBUG: // Unseen Break; Case information: System.out.println (message); break; Case Warning: Case Error: System.err.println (Message); break; }} Public string getDescription () {return details; }}  

Comments