I have been trying to follow a tutorial and in which they are basically using java 7 and currently I am working on a java 8 environment so I would want to know what would be java8 version of the code that I am trying to work on - currently I am getting alot of errors using Optional
which was suggested by eclipse to fix a few initial errors but I am stuck on some.
The java7 code as below:
@RequestMapping("/reservations")
public Reservation updateReservation1(ReservationUpdateRequest request) {
Reservation reservation = reservationRepo.findOne(request.getId());
reservation.setNumberOfBags((request.getNumOfBags());
reservation.setCheckedIn(request.getCheckedIn());
return reservationRepo.save(reservation);
}
java8 with error
@RequestMapping("/reservations")
public Optional<Reservation> updateReservation(ReservationUpdateRequest request) {
Optional<Reservation> reservation = reservationRepo.findById(request.getId());
reservation.setNumberOfBags((request.getNumOfBags());
reservation.setCheckedIn(request.getCheckedIn());
return reservationRepo.save(reservation);
}
here in java8 code eclipse ide is giving me error at line number 3 - that is when I am trying to set value into reservation.setNumberOfBags()
it shows The method setNumberOfBags(int) is undefined for the type Optional<Reservation>
- if any one can help ?