这是我的代码:
public void pollLocation()
{
myLocation.getLocation(this, new LocationResult()
{
public void gotLocation(Location location)
{
//I want to assign Location object from here...
}
});
}
private Location lastLocation; //...to here.
这可能吗?
最佳答案
是的。一般情况下直接写即可
lastLocation = location
但也许 LocationResult 类/接口(interface)也有一个名为 lastLocation 的字段。在这种情况下你必须写
OuterClassName.this.lastLocation = location
但是由于看起来您需要进行一些异步轮询,因此在没有同步的情况下执行此操作太危险了。此外,您也不会注意到 LastLocation 何时被设置。所以最好在外部类中使用同步setter。
关于java - 匿名类方法参数如何返回到原来的实例化类?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7225651/