How to work with enum in Java?

  • 0
    I got to the topic of transfers. And immediately from the first example, some troubles.
    An example is given.
    enum Apple {
        Apple1, Apple2, Apple3, Apple4, Apple5
    }


    public class App {
        public static void main(String[] args) {
            Apple apple;
            apple = Apple.Apple3;
    
            System.out.println("Значение apple: " + apple);
            System.out.println();
    
            apple = Apple.Apple2;
    
            if (apple == Apple.Apple2) {
                System.out.println("Переменная apple содержит Apple2.\n");
            }
    
            switch(apple) {
                case Apple1:
                    System.out.println("Сорт " + apple);
                    break;
                case Apple2:
                    System.out.println("Сорт " + apple);
                    break;
                case Apple3:
                    System.out.println("Сорт " + apple);
                    break;
                case Apple4:
                    System.out.println("Сорт " + apple);
                    break;
                case Apple5:
                    System.out.println("Сорт " + apple);
                    break;
            }
        }
    }


    In which part of the code should this enum * be written?
    I watched the video on enum, where the enum is stored in a separate file, as a class or interface.
    Everywhere I have not tried to write this enum, everywhere there are errors.
    I googled the text of the log, but I really couldn't find anything.
    This Java is hellishly difficult ...

    Examples of errors.
    Error:(1, 1) java: enums are not supported in -source 1.3
      (use -source 5 or higher to enable enums)

    Warning:(3, 12) java: as of release 5, 'enum' is a keyword, and may not be used as an identifier
      (use -source 5 or higher to use 'enum' as a keyword)


    Answer.
    Set a value from 5.
    Java Anonymous, Jul 24, 2020

  • 1 Answers
  • 0
    Java version error. use Java 5 or higher
    Anonymous

Your Answer
To place the code, please use CodePen or similar tool. Thanks you!