Here’s my code:
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.
Is this possible?
Yes. Generally you can just write
But maybe the LocationResult class/interface also has a field named lastLocation. In this case you have to write
But since it looks like you would do some asynchronous polling, it’s too dangerous to do this without synchronization. Also you wouldn’t notice when the lastLocation gets set. So it’s better to use a synchronized setter in the outer class.