intValue()
方法intValue()方法在java.lang包中可用。
intValue()方法用于返回此Short对象表示的值,该对象转换为int类型(通过强制转换)。
intValue()方法是一个非静态方法,只能由类对象访问,如果尝试使用类名访问该方法,则会收到错误消息。
从short转换为int时,intValue()方法不会引发异常。
语法:
public int intValue();
参数:
它不接受任何参数。
返回值:
此方法的返回类型为int,它返回此Short对象表示的转换后的值(从short类型转换为int类型)。
示例
//Java程序演示示例 //的intValue()短类的方法 public class IntValueOfShortClass { public static void main(String[] args) { //变量初始化 short value1 = 100; short value2 = 200; //它返回由此Short ob1对象表示的short值 //转换为int Short ob1 = new Short(value1); //显示ob1结果 System.out.println("ob1.intValue(): " + ob1.intValue()); //它返回此Short ob2对象表示的short值 //转换为int Short ob2 = new Short(value2); //显示ob2结果 System.out.println("ob2.intValue(): " + ob2.intValue()); } }
输出结果
ob1.intValue(): 100 ob2.intValue(): 200