class Person implements Comparable<Person> {
String name;
int age;
public Person(String name, int age) {
this.name = name;
this.age = age;
}
@Override
public int compareTo(Person other) {
return Integer.compare(this.age, other.age);
}
}
public class ComparePerson {
public static void main(String[] args) {
Person p1 = new Person("Alice", 25);
Person p2 = new Person("Bob", 30);
System.out.println(p1.compareTo(p2)); // -1 (Alice는 Bob보다 나이가 적음)
}
}