How to specialize a generic enum in Swift?

JAVA ENUM Random?

  • Why wont this code work? I need a way to randomly select values out of an enum. "enum e{One, Two, Three, Four, Five}; Random r = new Random(); e myEnum = r.nextInt(4);"

  • Answer:

    The first value in the enum will be nought. 'e' is not made a type (like in pascal) so your third line will not work unless you make a class 'e'. nextInt(int) returns an int. try this - public class myEnumTest { enum e{Nought, One, Two, Three, Four, Five}; public static void main (String args[]) { Random r = new Random(); int iran = r.nextInt(6); System.out.println (Integer.toString(iran)); System.out.println (e.values()[iran]); } }

chase at Yahoo! Answers Visit the source

Was this solution helpful to you?

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.