package com.lovecoding.day18.fanxing01;

import org.junit.Test;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;

public class TestFanXing {

    @Test
    public void test03(){
        //泛型方法的使用
        List<Integer> list = Arrays.asList(1, 2, 3, 4, 5);

        for (Integer integer : list) {
            System.out.println(integer);
        }

    }

    @Test
    public void test02(){

        Collection<Student> collection = new ArrayList();

//        collection.add(true);
//        collection.add("hello");
//        collection.add(new int[]{1,2});
        collection.add(new Student(1,"zs",22));
//        collection.add("world");

        //除了Student类型其他都会报错 避免转换异常
        // 集合中只能有 student类型

    }

    @Test
    public void test01(){

        Collection collection = new ArrayList();

        collection.add(true);
        collection.add("hello");
        collection.add(new int[]{1,2});
        collection.add(new Student(1,"zs",22));
        collection.add("world");

        for (Object o : collection) {

            if ( o instanceof Boolean ){
                System.out.println(o);
            }

            if (o instanceof String){
                System.out.println(o+"world");
            }

            if (o instanceof int[]){
                System.out.println(o);
            }

            //强制转换
            Student s = (Student) o;
            System.out.println(s);

        }

    }

}
