无法理解 LocationFinder.getFinder 参数列表中代码的工作方式,即类 new LocationFinder.Listener()
让我明白那是什么。
private LocationFinder locationFinder;
private ViewMaster viewMaster;
private synchronized void initLocationFinder() {
if (locationFinder == null) {
**locationFinder =LocationFinder.getFinder(new LocationFinder.Listener()
{
public void newLocation(double lat, double lon, int accuracy) {
DataModel.getInstance().setCurrentPosition(new GeoCoordinate(lat, lon, 0), accuracy);
refreshCurrentPositionOnMap();
if (viewMaster != null) {
viewMaster.draw();
}
}
});**
}
}
其中 LocationFinder 是一个抽象类
public static LocationFinder getFinder(Listener listener)
{
// returns finder which is reference of LocationFinder class
}
而Listener是一个接口
public interface Listener {
void newLocation(double lat, double lon, int accuracy);
}
然而 ViewMaster 是最终类扩展了 GameCanvas
public final class ViewMaster extends GameCanvas {
private volatile boolean refreshScreen = false;
public final void draw() {
refreshScreen = true;
}
这里 volatile boolean 是什么意思?