据我研究,Java 中的静态类只有在它是内部类时才有意义。
但是我刚刚看到这个例子,我想了解作者的意思,它是做什么的,它是如何工作的:
来自:http://developer.android.com/guide/topics/ui/actionbar.html
public static class TabListener<T extends Fragment> implements ActionBar.TabListener {
// a normal class with public constructor and TabListener methods
...
}
static 在这里意味着什么,它为什么起作用?
为什么他用 <T >
扩展 Fragment ?而不是正常的方式。
谢谢!
编辑: 哇,很快就有很多答案了。 感谢所有在这里分享知识的人。
我会将@npe 的回答标记为正确答案,因为他正确地指出示例周围的文本表明此类是成员。
还有一些关于堆栈溢出的奇怪格式,我刚刚修复了我原来的问题并在这里重复:
为什么他用 <T >
扩展 Fragment ?
@Ahmad 回答了那个问题,但我无法标记出两个正确答案。
最佳答案
无法将成员类声明为 static
- 它会发出编译器错误。
你的例子是关于一个成员类——引用the page you linked to :
For example, here's how you might implement the ActionBar.TabListener such that each tab uses its own instance of the listener:
所以页面声明,TabListener
是一个成员类。
关于java - Java中的公共(public)静态非内部类?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11222233/