package com.sf.reflectiontest;

import org.junit.Test;

import java.util.*;

/**
 * 反射的练习
 */
public class Test01 {

    @Test
    public void t1() throws ClassNotFoundException, InstantiationException, IllegalAccessException, NoSuchMethodException {
//        Student student = new Student();
//        Class<? extends Student> aClass = student.getClass();
//        Class<?> aClass1 = Class.forName("java.lang.String");
//        Class c1 = String.class;
//        String obj = new String();
//        Class c2 = obj.getClass();
//        Class c3 = Class.forName("java.lang.String");
//        Class c4 = ClassLoader.getSystemClassLoader().loadClass("java.lang.String");
//        System.out.println("c1 = " + c1);
//        System.out.println("c2 = " + c2);
//        System.out.println("c3 = " + c3);
//        System.out.println("c4 = " + c4);
//
//        System.out.println(c1 == c2);
//        System.out.println(c1 == c3);
//        System.out.println(c1 == c4);
        String str = "com.sf.reflectiontest.Student";
        Class<?> clazz = Class.forName(str);
        Object o = clazz.newInstance();
        System.out.println((Student)o);
        String name = clazz.getName();
        System.out.println(name);
        System.out.println(clazz.getSuperclass());
        System.out.println(Arrays.toString(clazz.getInterfaces()));
        ClassLoader classLoader = clazz.getClassLoader();
        System.out.println(classLoader);
        System.out.println(Arrays.toString(clazz.getConstructors()));
        System.out.println(Arrays.toString(clazz.getDeclaredMethods()));
        System.out.println(Arrays.toString(clazz.getMethods()));
        System.out.println(clazz.getMethod("setId",Integer.class));


        List<Integer> list = new ArrayList<>();
        list.add(1);
        list.add(2);
        list.add(3);
        list.get(1);

        Map map = new HashMap();
        map.put("user","zhangsan");
        map.get("user");

    }






    @Test
    public void t2(){
        String content = "中中国55kkfff";
        HashMap<Character, Integer> map = new HashMap<>();
        while (content.length() > 0) {
            Character c = content.charAt(0);
            content = content.substring(1);
            Integer count = map.get(c);
            if (count == null) {
                map.put(c, 1);
            } else {
                map.put(c, count + 1);
            }
        }

        Set<Map.Entry<Character, Integer>> entrySet = map.entrySet();
        for (Map.Entry<Character, Integer> entry : entrySet) {
            System.out.println(entry);
        }

    }
}
