(studentElement)arraylist.get(0);
解决方案 »
- 多线程的操作问题,问问该怎么做,怎么处理??
- 下面的方法swap为什么无法交换实际参数的值?(王晓东版课后题)
- java 读XML文件的困扰
- 我作了个TCP通信,服务端接收信息后不能返回给客户端信息
- 为何总是出现这样一个问题???
- 要写个监听数据库的方法,怎么写好?
- ~ 怎么用?
- 多线程用HttpURLConnection下载图片问题,请教大家
- 两点不名,请指点!
- client-server 的socket程序,刚开始运行正常,运行一段时间后出现connection reset by peer错误,如何解决??
- 怎样把C中的typedef enum在Java里表示?
- 求一个生成随机随机数的方法
用((StudentElement)stu2).name就行了。
这叫做cast
class studentElement
{
String name;
int score;
}
public class test
{
public static void main(String[] args)
{
ArrayList arraylist=new ArrayList();
studentElement stu=new studentElement();
Object stu2=new Object();
String a;
stu.name="monkey";
stu.score=90;
arraylist.add(stu);
stu2=arraylist.get(0);
a=((studentElement)stu2).name;
System.out.println(a);
}
}
这样做,符合要求,不报错