Charles
Charles

Reputation: 3774

Using Nested Enum as Parameter in Seperate Package

New to java and have a question related to packages.

I like to keep objects organized in namespaces and ran into a problem with enums that I cannot figure out.

Say I have a nested enum like this:

package Project;
public class Foo
{
    public enum Bar { One, Two, Three };
}

I want to do something like this

package Project.Attributes;
public class Foo
{
    public setBar( Project.Foo.Bar bar ) {}
}

But I am getting name conflicts and unknown package 'Foo' errors.

How can I achieve this?

Upvotes: 0

Views: 281

Answers (2)

Bozho
Bozho

Reputation: 597124

You need to have a semicolon at the end of the first line. And use lowercase letters for package names

Upvotes: 2

Aravind Yarram
Aravind Yarram

Reputation: 80186

It should work after below corrections

  1. semicolon after the package declaration
  2. add void return type for setBar(...) method

One more suggestion is to use small case for package names.

package project;

public class Foo
{
    public enum Bar {
        One, Two, Three
    };
}


package project.attributes;

public class Foo
{
    public void setBar(project.Foo.Bar bar)
    {
    }
}

Upvotes: 3

Related Questions