int 是4字节, short 是2字节的, 如果将int(Integer)转成short(Short), 那么必须强制转换,否则会报编译异常. 但是, 当int(Integer)是一个final时, 可以直接转换, 不必强转.如: short t = 1;(正确) int t = 1; short tt = t; (出错) final int t = 1; short tt = t; (正确)
因为在学习集合时知道集合里存放的对象都是Object类型,取出的时候需要强制类型转换为目标类型(使用泛型集合不需要),如int a = (Integer)arrayList.get(0):然后我们就会发现,为什么要强制转换为Integer,而不是int呢?int与Integer有什么区别呢? 1.基本类型与包装类区别 int是基本类型,直接存数值:如: int i = 5://直接在栈中分配空间,存放5这个数值 Integer是int的包装类,是类,拥有方法:如: Integer i = new
Integer常量池 问题1 public class Main_1 { public static void main(String[] args) { Integer a = 1; Integer b = 2; Integer c = 3; Integer d = 3; Integer e = 321; Integer f = 321; Long g = 3L; Long h = 2L; System.out.println(c == d); System.out.println(e ==
class Array Arrays are ordered, integer-indexed collections of any object. Array indexing starts at 0, as in C or Java. A negative index is assumed to be relative to the end of the array—that is, an index of -1 indicates the last element of the array
NSLog常见输出格式 Table 1 Format specifiers supported by the NSString formatting methods and CFString formatting functions Specifier Description %@ Objective-C object, printed as the string returned by descriptionWithLocale: if available, or description o
介绍: Java中有8种基本类型,分别是boolean, char, byte, short, int, long, float, double.他们的长度固定,不是对象.对于有必要将基本类型作为对象处理的情况,java提供了包装器类,这样有个好处是Java编译器和运行时能够更容易的进行优化.由于java的可移植性,每个类型在不同的平台上大小一致. 代码实现: package self; /** * Created by Jimmy on 2015/5/18. */ public class s
装箱 在Java SE5之前,如果要生成一个数值为10的Integer对象,必须这样进行: Integer i = new Integer(10); 而在从Java SE5开始就提供了自动装箱的特性,如果要生成一个数值为10的Integer对象,只需要这样就可以了: Integer i = 10; 这个过程中会自动根据数值创建对应的 Integer对象,这就是装箱. 拆箱 那什么是拆箱呢?顾名思义,跟装箱对应,就是自动将包装器类型转换为基本数据类型: Integer i = 10; //装箱 i