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.

aUserHimself
  • 1,589
  • 2
  • 17
  • 26
ronaldfisher
  • 21
  • 1
  • 6

2 Answers2

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);
talex
  • 17,973
  • 3
  • 29
  • 66
1

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

if you do,

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

output will be AUGUST

NikhilP
  • 1,508
  • 14
  • 23