使用super();在Java中

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 {

那么在那一点上没有延伸所以超级引用了什么?指某东西的用途

<? extends >

我以前从未见过.

提前致谢…

解决方法:

private final Class<? extends FragmentActivity> activityClass;

这声明了一个名为activityClass的字段,该字段是私有的(仅在声明它的类中可见)和final(没有重新分配).它的类型是Class<?扩展FragmentActivity> (它是泛型类型Class<T>的参数化类型或(类型)实例化,其中T是类型参数).使用泛型类型时,它们称为参数化类型,并为type参数提供类型参数.这里的类型参数是?扩展FragmentActivity(实际上是wildcard with an upper bound,这里的上限恰好是FragmentActivity.

这意味着activityClass可以引用一个Class实例,它表示FragmentActivity类本身或其任何子类(例如FragmentActivity.class).

上一篇:26 01 继承对象的相互转换


下一篇:(Has-A vs. Is-A)如何布局我的程序架构? (JAVA)