为什么我们在不允许的情况下创建了 abstract class 的实例?
Why have we created an instance of abstract class when we are not allowed?
此人已完成:"protected GoogleApiClient mGoogleApiClient;" 在以下代码中:
Android Maps Get Longitude and Latitude
但 GoogleApiClient 是抽象的 class。
如何创建它的实例?
摘要 class 如此处所述:
https://developers.google.com/android/reference/com/google/android/gms/common/api/GoogleApiClient
不应该扩展为抽象classes只能扩展吗?
它没有直接实例化。如果您查看您提供的 link 中的代码,这就是 GoogleApiClient
的 subclass 实例的生成方式:
mGoogleApiClient = new GoogleApiClient.Builder(this)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.addApi(LocationServices.API)
.build();
我们在这里不使用 new
关键字,而是使用静态 class Builder
中的 build
方法
此人已完成:"protected GoogleApiClient mGoogleApiClient;" 在以下代码中:
Android Maps Get Longitude and Latitude
但 GoogleApiClient 是抽象的 class。
如何创建它的实例?
摘要 class 如此处所述: https://developers.google.com/android/reference/com/google/android/gms/common/api/GoogleApiClient
不应该扩展为抽象classes只能扩展吗?
它没有直接实例化。如果您查看您提供的 link 中的代码,这就是 GoogleApiClient
的 subclass 实例的生成方式:
mGoogleApiClient = new GoogleApiClient.Builder(this)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.addApi(LocationServices.API)
.build();
我们在这里不使用 new
关键字,而是使用静态 class Builder
build
方法