0

I have an enum and I need to bind these values to the switch in another class, Help please, I'm confused

public enum GSProccesingType {
    bigCover,
    cover,
    other
}

class Test {
 switch (GSProccesingType){
        case bigCover:
        break;
        case cover:
            break;
        case default:
    }
 }

enter image description here

Ravi
  • 30,829
  • 42
  • 119
  • 173
Mike Mclaren
  • 211
  • 3
  • 9

1 Answers1

0

You'll have to create an object first. Then use that object in switch statement. Like below:

GSProccesingType type = GSProccesingType.cover;.   // type will hold any one of the enum values. Cover is one such value
switch(type){...}

For your example you need to put bigCover in switch

Pankaj Singhal
  • 15,283
  • 9
  • 47
  • 86
  • why .cover if i have in enum 3 values: bigCover, cover and other? – Mike Mclaren Sep 04 '18 at 05:38
  • It's an example. The object will hold any one of the enum values – Pankaj Singhal Sep 04 '18 at 05:38
  • I can not understand .cover And what is this? – Mike Mclaren Sep 04 '18 at 05:40
  • For your case bigCover holds the value of the enum. Put that variable in the switch. – Pankaj Singhal Sep 04 '18 at 05:43
  • @TerletskiyAlexander Perfect example, when you don't read the topic completely and directly jumped into implementation.You should first understand `what is ENUM` – Ravi Sep 04 '18 at 05:45
  • @TerletskiyAlexander are you coding with C before? In C language, you can get the enum value right away. But with Java, you need to get first the enum parent GSProccessingType. Also you need a non-constant expression when passing to switch statement. For example `GSProccesingType yourExpression; yourExpression = GSProccesingType (dot) (your selected enum); switch ( yourExpression){ case GSProccesingType.bigCover: break; case GSProccesingType.cover: break; case GSProccesingType.other: break; case default: ;}` – Leandro Keen Zapa Sep 04 '18 at 06:03