Enum describeConstable() in Java

describeConstable(): This method is available in java.lang.Enum class of Java.

Syntax:

Optional<EnumDesc<Colour>> java.lang.Enum.describeConstable()

Returns an enum descriptor EnumDesc for this instance, if one can be constructed, or an empty Optional if one cannot be.

Parameters: NA

Returns: An Optional containing the resulting nominal descriptor, or an empty Optional if one cannot be constructed.

Exceptions: NA

Approach

Java

enum Colour {
    RED, GREEN, GRAY, ORANGE
}

public class EnumdescribeConstable {
    public static void main(String[] args) {

        System.out.println(Colour.RED.describeConstable());
    }
}

Output:

Optional[EnumDesc[Colour.RED]]


No comments:

Post a Comment