这之间有什么区别(性能和其他):
public class MyPlaceMapper implements PlaceHistoryMapper {
@Override
public String getToken(Place place) {
if(place instanceof HomePlace)
return "home";
else
return null;
}
@Override
public Place getPlace(String token) {
if(token.equals("home"))
return new HomePlace();
else
return null;
}
}
和:
public class MyPlaceMapper implements PlaceHistoryMapper {
// Singleton HomePlace to inject and reuse over and over again
private HomePlace homePlace;
// Getter/setter for homePlace...
@Override
public String getToken(Place place) {
if(place instanceof HomePlace)
return "home";
else
return null;
}
@Override
public Place getPlace(String token) {
if(token.equals("home"))
return homePlace;
else
return null;
}
}
换句话说,我是否Place
一遍又一遍地重复使用相同的“单例”,或者我每次请求时都实例化一个新的,有什么区别。
此外,对于Activity
s 内部的相同问题ActivityMapper
。再次感谢!