package com.sf.day16;

import org.junit.Test;

import java.util.Arrays;
import java.util.Comparator;
import java.util.Iterator;
import java.util.TreeSet;

public class TestUser {

    @Test
    public void t1(){
        TreeSet<User> treeSet = new TreeSet<User>(new Comparator<User>() {
            @Override
            public int compare(User o1, User o2) {
                if(o1 instanceof User && o2 instanceof User){
                    User user1 = (User) o1;
                    User user2 = (User) o2;
                    return user1.age - user2.age;
                }
                throw new RuntimeException("类型不匹配");
            }
        });
        treeSet.add(new User("Tom",12));
        treeSet.add(new User("Rose",23));
        treeSet.add(new User("Jerry",2));
        System.out.println(treeSet);
    }

//    @Override
//    public int compare(Object o1, Object o2) {
//        if(o1 instanceof User && o2 instanceof User){
//            User user1 = (User) o1;
//            User user2 = (User) o2;
//            return user1.age - user2.age;
//        }
//        throw new RuntimeException("类型不匹配");
//    }
}
