How do I get the value from an enum? | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
0

How do I get the value from an enum?

Say I write an enum called ExampleEnum. The constants I write in it are AND, OR, NOT How do i check if the value of a ExampleEnum object is one of those ? For instance I have: public boolean checkValue() which checks if the value of the enum is AND or OR and returns true for them, otherwise returns false. Does doing ā€œif (this == ExampleEnum.NOT)ā€ and so forth work? Or is there another keyword Iā€™m supposed to be using?

11th Apr 2019, 7:01 PM
Jamie Charles
1 Resposta
+ 2
I think it should work. Here is an example with switch: https://www.sololearn.com/learn/Java/2174/?ref=app And here is my example: https://code.sololearn.com/ccKce03uWJ7b/?ref=app
11th Apr 2019, 9:48 PM
Denise RoƟberg
Denise RoƟberg - avatar