我正在看一个程序,它包含一条我不理解的行。可以解释一下这段代码在Java中的含义吗?
NoticeBoard notice = (NoticeBoard) o;
那段代码在干什么?
这条线就是从这里取(张贴这一点,因为你们可能想了解该行的完整上下文):
import java.util.Observable;
import java.util.Observer;
class NoticeBoard extends Observable
{
private String theNotice = "";
public void setTheNotice(final String notice)
{
theNotice = notice;
setChanged();
notifyObservers();
}
public String getTheNotice()
{
return theNotice;
}
}
class NoticeBoardObserver implements Observer
{
public void update(Observable o, Object arg)
{
NoticeBoard notice = (NoticeBoard) o;
System.out.println(notice.getTheNotice());
}
}
class Main
{
public static void main(String args[])
{
NoticeBoard floor4 = new NoticeBoard();
NoticeBoardObserver anObserver = new NoticeBoardObserver();
floor4.addObserver(anObserver);
floor4.setTheNotice("Its summer");
}
}
它的类型转换。 – Layke 2011-04-17 00:07:10
[The Java Tutorials - Learning the Java language - Inheritance](http://download.oracle.com/javase/tutorial/java/IandI/subclasses.html) – BalusC 2011-04-17 00:09:25