【发布时间】:2013-06-03 06:46:30
【问题描述】:
package com.example.mapdemo;
import android.app.ListActivity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ListAdapter;
import android.widget.ListView;
import com.example.mapdemo.view.FeatureView;
/**
* The main activity of the API library demo gallery.
* <p>
* The main layout lists the demonstrated features, with buttons to launch them.
*/
public final class MainActivity extends ListActivity {
/**
* A simple POJO that holds the details about the demo that are used by the List Adapter.
*/
private static class DemoDetails {
/**
* The resource id of the title of the demo.
*/
private final int titleId;
/**
* The resources id of the description of the demo.
*/
private final int descriptionId;
/**
* The demo activity's class.
*/
private final Class<? extends FragmentActivity> activityClass;
public DemoDetails(
int titleId, int descriptionId, Class<? extends FragmentActivity> activityClass) {
super();
this.titleId = titleId;
this.descriptionId = descriptionId;
this.activityClass = activityClass;
}
}
当涉及到这段代码时,我发现我需要更好地理解两件事。首先,我试图确定以下内容的确切含义:
private final Class<? extends FragmentActivity> activityClass;
其次,我很好奇 super() 叫什么;因为当 DemoDetails 被定义时,它被定义为:
private static class DemoDetails {
所以那时没有扩展,那么 super 引用的是什么?使用
<? extends >
我从来没有见过。
提前谢谢...
【问题讨论】:
-
Java 中的所有类都派生自
Object,所以在这种情况下,super()已过时,可能因为生成了构造函数而存在这一行。 -
@MarcoForberg:如果这里没有显式调用
super(),那么无论如何都会隐式调用它。 -
@MarcoForberg:我很确定 ;) 请参阅 Java 语言规范,第 12.5 节创建新类实例第 3 点,Link here
-
好吧,今天学到了一些东西,ty ;)
标签: java android extends super