非法修改错误的静态类 [英] Illegal modifier error for static class

查看:182
本文介绍了非法修改错误的静态类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开发一个Android应用程序,但已经打了一下的砖墙,我不断收到错误:

I'm developing an android application but have hit a bit of a brick wall, I keep getting the error:

Illegal modifier for the class FavsPopupFragment; only public, abstract & final are permitted

这件事发生之后这个答案另一个SO问题之后。这里是code,我有:

This happened after following this answer to another SO question. Here is the code that I have:

package com.package.name;

/* Imports were here */

public static class FavsPopupFragment extends SherlockDialogFragment {

    static FavsPopupFragment newInstance() {
        FavsPopupFragment frag = new FavsPopupFragment();
        return frag;
    }
}

出现在类名中的错误。我不明白为什么这不会工作,请大家帮忙。谢谢你。

The error appears on the class name. I dont understand why this wont work, please help. Thank you.

推荐答案

您不能创建一个顶级静态类;这就是编译器是想告诉你。另外看看这里作为答案为什么的是这种情况。要点是:

You can't create a top level static class; that's what the compiler is trying to tell you. Also have a look at the answer here as to why this is the case. The gist is:

什么是静态归结为是该类的实例可以   站在自己。或者,反过来:​​一个非静态内部类   (=实例内部类),不能没有外部的一个实例中存在   类。由于顶级类不具有外部类,它不能   是什么,但静态的。

What the static boils down to is that an instance of the class can stand on its own. Or, the other way around: a non-static inner class (= instance inner class) cannot exist without an instance of the outer class. Since a top-level class does not have an outer class, it can't be anything but static.

由于所有的顶级类是静态的,具有static关键字   顶层类定义是没有意义的。

Because all top-level classes are static, having the static keyword in a top-level class definition is pointless.

这篇关于非法修改错误的静态类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆