Click here to Skip to main content
14,697,262 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi...

Ive seen some examples in http://docs.oracle.com/[^] that contains enums with some variables inside each enum objects like the example below...


public enum Planet {
    MERCURY (3.303e+23, 2.4397e6),
    VENUS   (4.869e+24, 6.0518e6),
    EARTH   (5.976e+24, 6.37814e6),
    MARS    (6.421e+23, 3.3972e6),
    JUPITER (1.9e+27,   7.1492e7),
    SATURN  (5.688e+26, 6.0268e7),
    URANUS  (8.686e+25, 2.5559e7),
    NEPTUNE (1.024e+26, 2.4746e7);

    private final double mass;   // in kilograms
    private final double radius; // in meters
    Planet(double mass, double radius) {
        this.mass = mass;
        this.radius = radius;
    }


And Ive tried to create an enum like the same..

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

    }
    enum Days
    {
        Monday(false), Tuesday(false), Wednesday(false), Thursday(false), Friday(false), Saturday(true), Sunday(true)
    }
}


But the program doesnt run and it says
constructor Days in enum Days cannot be applied to given types;
required: no argument
found: boolean
reason: actual and formal arguments lists differ in length"

What does that really mean ?

And how can I create some enums with booleans values ?
Posted
Updated 5-Apr-14 8:10am
v2

1 solution

It means that you have not created a constructor in your enum which takes a boolean value. You need to change it so it looks like:
public enum Day
{
    Monday(false),
    Tuesday(false),
    Wednesday(false),
    Thursday(false),
    Friday(false),
    Saturday(true),
    Sunday(true);

    private final boolean weekEnd;

    Day(boolean weekEnd) {
        this.weekEnd = weekEnd;
    }
    bool isWeekend()
    {
        return weekEnd;
    }
}

[edit]
fixed type to boolean
[/edit]
   
v2
Comments
M­­ar­­­­k 6-Apr-14 7:04am
   
public enum ??

Is it necessary to declare an enum as a public enum to use enums with variables inside brackets ??
Richard MacCutchan 6-Apr-14 7:58am
   
No, the public keyword has nothing to do with the content of the object, it is about visibility.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900