0

I'm doing an assignment in Java where I'm supposed to use the enumeration type MONTH that I've imported in my project. My teacher has written that "There is a special function that will convert a number to it's month: Month.month(8)".

I've written Month month = Month.month(4); (where the variable month should have the value april), but it says that

"the method month is undefined for the type month".

As I understand it, Java interprets the "Month" after the equal sign as a data/enumeration type, but I want it to be the class from which I use the function month (they both have the name Month). My classmates has used it without a problem and as far as I can see I've imported my teachers code correctly.

Eternally grateful for any help.

1
  • 2
    Please add code. Commented Oct 4, 2017 at 10:02

2 Answers 2

3

If you have two classes (or enums) with same name you can use FQN (Fully Qualified Name).

For example if you have enum Month in package myenums and class Month in package myclasses you can write:

myenums.Month month = myclasses.Month.month(4);
Sign up to request clarification or add additional context in comments.

Comments

1

you can use Month.of(monthNumber).name();

if you do,

Month month = Month.of(8);
System.out.println(month);

output will be AUGUST

1 Comment

@ronaldfisher your welcome, you can upvote if it solved your problem.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.