Ordenar ArrayList de objetos propios por campo en Java
¡Hola a todos! Soy nuevo en Java y me encontré con un problema al ordenar una lista de objetos. Tengo una clase `Book` con campos `title` (String) y `year` (int). Almaceno varios libros en un `ArrayList`, y ahora necesito ordenar esta lista por año de publicación, del más antiguo al más nuevo.
He oído hablar de `Collections.sort()`, pero solo funciona para listas de números o strings. Cuando intento aplicarlo a mi lista de libros, el compilador da un error: "The method sort(List) in the type Collections is not applicable for the arguments (ArrayList)".
Aquí está mi código de ejemplo:
```java
import java.util.ArrayList;
import java.util.Collections;
public class Book {
String title;
int year;
public Book(String title, int year) {
this.title = title;
t