Reputation: 344
I am creating a heap program that stores java.time.LocalDate objects. Although I'm having trouble creating a temp variable for a LocalDate. I may be making a minor mistake, but here is my code
private void trickleUp(int n) {
int pIndex;
if (n != 0) {
pIndex = getParentIndex(n);
if (heapA[pIndex].isAfter(heapA[n])) {
LocalDate temp = new LocalDate(heapA[pIndex]);
heapA[pIndex] = heapA[n];
heapA[n] = temp;
trickleUp(pIndex);
}
}
}
Im getting the error 'The constructor LocalDate(LocalDate) is undefined'
Upvotes: 1
Views: 720
Reputation: 691973
LocalDate is an immutable class. There is no reason to create a copy of another LocalDate instance. You just need
LocalDate temp = heapA[pIndex];
You should always check the javadoc of the classes you're using. In that case: http://docs.oracle.com/javase/8/docs/api/java/time/LocalDate.html. And indeed, as the error message says, there is no constructor in LocalDate that takes a LocalDate as argument. In fact, there is no constructor at all. LocalDate instances are typically created by transforming other objects to LocalDate, or by using one of the static factory methods listed in the javadoc.
Upvotes: 5