强软弱虚引用和强弱类型

    xiaoxiao2021-04-14  31

    强/软/弱/虚引用:与垃圾回收GC机制有关

    强/弱类型:与变量声明有关

    下图是对比:

    弱类型: var x = 1; alert(typeof x);//number x = '1'; alert(typeof x);//string x = null; alert(typeof x);//object 强类型: package demo; /** * 强类型测试 * @author TCM * @since 2017年4月6日下午9:46:16 */ public class StrongType { public static void main(String[] args) { Integer i = 1; if (i instanceof Integer) { System.out.println("i是int的封装类!"); } //i = '1';//报错:Type mismatch: cannot convert from char to Integer } }

    转载请注明原文地址: https://ju.6miu.com/read-669808.html

    最新回复(0)