5

I'm learning Kotlin and Spring and was developing mini project for learning experience. This function is for updating todo's which are already created/added and find it by Id and update the data. But I get Unresolved Reference: copy, and no documentation found.

fun putTodo(id: Long, newTodo: Todo): ResponseEntity<Todo> = todoRepository.findById(id).map { currentTodo -> val updatedTodo: Todo = currentTodo.copy( title = newTodo.title, status = newTodo.status ) ResponseEntity.ok().body(todoRepository.save(updatedTodo)) }.orElse(ReponseEntity.notFound().build()) 

2 Answers 2

11

In order for copy() to exist, Todo must be data class.

Sign up to request clarification or add additional context in comments.

Comments

0

Posted on 15 Jun 2024. I just faced a same problem a while ago. For this private fun enterOperation(operations: CalculatorOperations) { if (state.number1.isNotBlank()){ state = state.copy(operation = operations)}} As I checked the state i have been referencing was not a data class therefore I changed the code and Its work.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.