G
G
gleendo2016-10-23 20:20:33
Java
gleendo, 2016-10-23 20:20:33

How to work with enum in Java?

Reached the topic about 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 what part of the code should I write this enum*?
I watched a video on enum, where enum is stored in a separate file, as a class or interface.
Wherever I have not tried to write this enum, there are errors everywhere.
Googled the text of the log, but did not really 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 value from 5.
0c0a17fd150e4a06aab4a226cff38771.png

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
NoMoneyException, 2016-10-23
@eugene_leshchinskiy

java version error. use Java 5 or higher

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question