1,
short s=0;
s=s+1;  有错,1默认是int,从int到short必须强制转换而s+=1没错,怎样理解?是先把s转为int还是把1转为short? s+=1应该就是s=s+1才对啊。
2,
java.lang.reflect.Array有什么用?
为什么Array.newInstance(java.lang.String.class.getComponentType(),10);会错?

解决方案 »

  1.   

    1.s=s+1是short=short+int,所以要强转,是取数相加后再赋值
     s=s+1相当于short的自增一,是在寄存器中直接加,所以不用强转2.
    你看一下getComponentType方法的doc,你直接对String.class调用,其返回值是null,当然出错了
         Returns the <code>Class</code> representing the component type of an
         array.  If this class does not represent an array class this method
         returns null.
      

  2.   

    s+=1和s=0的原理一样,都会把int隐式转为short.
    但是s=s+1,(s+1)是Int,要显式转化为short