当前位置: 技术问答>java相关
还是那个简单的java.util.Vector类函数使用问题
来源: 互联网 发布时间:2015-01-11
本文导语: 定义一个java.util.Vector类,Vector v;v.addElement(new Integer(8)); int i=v.elementAt(0);编译说类型错误,why? 有位大侠说这样做:Integer k = (Integer)v.elementAt(0); int i = k.intValue(); 我试了还是不行,jbuilder说:incom...
定义一个java.util.Vector类,Vector v;v.addElement(new Integer(8));
int i=v.elementAt(0);编译说类型错误,why?
有位大侠说这样做:Integer k = (Integer)v.elementAt(0);
int i = k.intValue();
我试了还是不行,jbuilder说:incompatible types;found java.lang.Object,required:java.lang.Integer
int i=v.elementAt(0);编译说类型错误,why?
有位大侠说这样做:Integer k = (Integer)v.elementAt(0);
int i = k.intValue();
我试了还是不行,jbuilder说:incompatible types;found java.lang.Object,required:java.lang.Integer
|
编译通过,输出8,
import java.awt.*;
import java.awt.event.*;
import java.util.Vector;
public class MyApp
{
public MyApp()
{
}
public static void main(String args[])
{
System.out.println("Starting App");
MyApp f = new MyApp();
Vector v = new Vector();
v.addElement(new Integer(8));
int i = ((Integer)v.elementAt(0)).intValue();
System.out.println(i);
System.exit(0);
}
}
import java.awt.*;
import java.awt.event.*;
import java.util.Vector;
public class MyApp
{
public MyApp()
{
}
public static void main(String args[])
{
System.out.println("Starting App");
MyApp f = new MyApp();
Vector v = new Vector();
v.addElement(new Integer(8));
int i = ((Integer)v.elementAt(0)).intValue();
System.out.println(i);
System.exit(0);
}
}