在使用Google Places API时,我遇到了这段代码:
Place place = PlacePicker.getPlace(this, data);
这很好用。然而,在探索中,我遇到了一些我不了解的事情。 地点是一个只有getter方法的界面。以下是接口Place的代码:
public interface Place extends Freezable<Place> {
int TYPE_OTHER = 0;
/* ... Similar type declarations */
int TYPE_SYNTHETIC_GEOCODE = 1029;
int TYPE_TRANSIT_STATION = 1030;
String getId();
List<Integer> getPlaceTypes();
CharSequence getAddress();
Locale getLocale();
CharSequence getName();
LatLng getLatLng();
LatLngBounds getViewport();
Uri getWebsiteUri();
CharSequence getPhoneNumber();
float getRating();
int getPriceLevel();
CharSequence getAttributions();
}
PlacePicker.getPlace()的代码如下:
public class PlacePicker extends zza {
public static final int RESULT_ERROR = 2;
private PlacePicker() {
}
public static Place getPlace(Context context, Intent intent) {
return zza.getPlace(context, intent);
}
/* Rest code of the class */
}
此处 zza 类的签名为protected abstract static class zza
。
编辑: 类 zza
的代码abstract class zza {
public static final int RESULT_ERROR = 2;
zza() {
}
public static Place getPlace(Context context, Intent intent) {
zzx.zzb(intent, "intent must not be null");
zzx.zzb(context, "context must not be null");
return (Place)zzc.zza(intent, "selected_place", PlaceImpl.CREATOR);
}
public static Status getStatus(Context context, Intent intent) {
zzx.zzb(intent, "intent must not be null");
zzx.zzb(context, "context must not be null");
return (Status)zzc.zza(intent, "status", Status.CREATOR);
}
protected abstract static class zza {
protected final Intent mIntent;
public zza(String var1) {
this.mIntent = new Intent(var1);
this.mIntent.setPackage("com.google.android.gms");
}
protected Intent build(Activity activity) throws GooglePlayServicesRepairableException, GooglePlayServicesNotAvailableException {
Theme var2 = activity.getTheme();
TypedValue var3 = new TypedValue();
TypedValue var4 = new TypedValue();
if(var2.resolveAttribute(16843827, var3, true) && !this.mIntent.hasExtra("primary_color")) {
this.mIntent.putExtra("primary_color", var3.data);
}
if(var2.resolveAttribute(16843828, var4, true) && !this.mIntent.hasExtra("primary_color_dark")) {
this.mIntent.putExtra("primary_color_dark", var4.data);
}
GoogleApiAvailability.getInstance().zzak(activity);
return this.mIntent;
}
}
}
现在我的问题是,当所有类都没有实现Place
接口时,place.getName()
如何工作?编写方法定义到底在哪里?