Java中数组是对象


package io;
import java.io.File;
public class GetAllSubclass {
    public static void main(String[] args) {
        File rootFile = new File(GetAllSubclass.class.getResource("/").getFile().replaceFirst("/", ""));
        setSonList(rootFile, rootFile.getPath() + "\\", GetAllSubclass.class);
    }
    public static <T> void setSonList(File rootFile, String parentDirectory, Class<T> parentClass) {
        if (rootFile.isDirectory()) {
            File[] files = rootFile.listFiles();
            for (File file : files) {
                setSonList(file, parentDirectory, parentClass);
            }
        } else {
            String className = null;
            try {
                if (rootFile.getPath().indexOf(".class") != -1) {
                    className = rootFile.getPath().replace(parentDirectory, "").replace(".class", "").replace("\\", ".");
                    Class<?> classObject = Class.forName(className);
                    classObject.asSubclass(parentClass);
                    System.out.println(className + " 是 " + parentClass + " 的子类");
                }
            } catch (ClassNotFoundException e) {
                System.err.println("找不到类 " + className);
            } catch (ClassCastException e) {
                System.err.println(className + " 不是 " + parentClass + " 的子类");
            }
        }
    }
}
class Sub1 extends GetAllSubclass {
}
class Sub2 extends GetAllSubclass {
}

Java中数组有自己的方法和成员变量,数组绝逼是对象,同事Super[]   superArr;Sub[],arraylist是源码解析

 

public class ArrrAndGenericTest {
    public static void main(String[] args){
        test();
    }
    public static void test(){
        Byte a = 127;
        Byte b = 127;
        System.out.println(++a);
        add(++a);
        System.out.println("a =" + a);
        add(b);
        System.out.println("b =" + b);
    }
    public static void add(Byte b){
        b++;
    }

    public static void isArrayMethod() {
        // 判断Java对象是否为数组
        Integer[] ia = new Integer[6];
        Number[] na;
        String[] strs = new String[7];
        System.out.println(ia instanceof Number[]);
        System.out.println(ia instanceof Integer[]);
        System.out.println(ia.getClass().isArray());
        System.out.println(strs.getClass());
    }
    /**
     * Java的设计原则是,代码只要是在编译时没有出现警告,
     * 就不会遇到运行时ClassCastException
     * 1处引发ArrayStoreException
     */
    public static void ArrClassCastTest(){
        Integer[]  ia = new Integer[6];
        Number[] na = ia;
        na[0] = 0.5;//1
        
        List<Integer> iList = new ArrayList<Integer>();
        List<Number> nlist = iList;//出现变异错误
                
        
    }
    
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值