How do I get the value from an enum? | Sololearn: Learn to code for FREE!
¡Nuevo curso! ¡Todo programador debería aprender IA Generativa!
Prueba una lección gratuita
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 Respuesta
+ 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