shas
shas

Reputation: 418

IntelliJ can't find LocalDate.of() method

I am doing a program where I need to use this line

this.currentDay = new LocalDate.of(tmp.getYear(),tmp.getMonth(),1);

InteliJ find the .of and propose me to use it, which is what i want to do, but as soon as i click on it, the of become red and an error bubble say "cannot resolve symbol of"

for context the problematic function is in this class

public class DayOfVacation {
  LocalDate currentDay;
  User user;
  Vacation vacation;

  public DayOfVacation(User user, Vacation vacation){
    LocalDate tmp = LocalDate.now();
    this.currentDay = new LocalDate.of(tmp.getYear(),tmp.getMonth(),1);

  }
}

Upvotes: 2

Views: 1547

Answers (2)

Michael
Michael

Reputation: 44210

Because you're doing new LocalDate.of(, the only possible interpretation in Java is that you're looking to instantiate an inner class called of located within LocalDate, which has a constructor which takes three parameters. There is no such thing, which is why you get the error that you do.

This is not an inner class. It's a static method. You must remove the new keyword.

Upvotes: 2

Karol Dowbecki
Karol Dowbecki

Reputation: 44970

When calling a static LocalDate.of() method you can't use the new operator. Your code should be:

this.currentDay = LocalDate.of(tmp.getYear(), tmp.getMonth(), 1);

Upvotes: 2

Related Questions