No enclosing instance of type SearchCommand is available due to some intermediate constructor invoca
来源:互联网 发布:金华亿途网络 编辑:程序博客网 时间:2024/06/12 04:06
public class SearchCommand extends Command {
private static final String ACTION = "search";
public SearchCommand() {
this(ACTION, new SearchCommandHandler());//error: No enclosing instance of type SearchCommand is available due to some intermediate constructor invocation
}
public SearchCommand(String action, CommandHandler handler) {
super(action, handler);
}
class SearchCommandHandler implements CommandHandler {
@Override
public void execute(PrintStream out, Properties args) {
out.println(args.toString());
}
}
private static final String ACTION = "search";
public SearchCommand() {
this(ACTION, new SearchCommandHandler());//error: No enclosing instance of type SearchCommand is available due to some intermediate constructor invocation
}
public SearchCommand(String action, CommandHandler handler) {
super(action, handler);
}
class SearchCommandHandler implements CommandHandler {
@Override
public void execute(PrintStream out, Properties args) {
out.println(args.toString());
}
}
}
原因:
http://stackoverflow.com/questions/2741066/why-does-a-sub-class-class-of-a-class-have-to-be-static-in-order-to-initialize-t
Basically an inner class (without the static modifier) has an implicit reference to an instance of its outer class, so it can't be created until the outer class is created. By creating one on the call tothis
it can't reference the outer class yet because the outer class isn't constructed much at all until after the call to super. The case that works for you, the assignment to head happens after the (implicit) call to super so the class is constructed enough to get a reference to it.
- No enclosing instance of type SearchCommand is available due to some intermediate constructor invoca
- No enclosing instance of type WallpaperService is available due to some intermediate constructor inv
- No enclosing instance of type Test37 is available due to some intermediate constructor invocation
- No enclosing instance of type * is accessible.
- No enclosing instance of type is accessible.
- No enclosing instance of type ThreadTest is accessible.错误解决
- 【JAVA001】No enclosing instance of type XXX is accessible.
- No enclosing instance of type E is accessible
- No enclosing instance of type E is accessible
- Java no enclosing instance of type * is accesible
- 黑马程序员--No enclosing instance of type E is accessible.
- No enclosing instance of type xxx is accessible
- Java编译错误“No enclosing instance of type AA is
- No enclosing instance of type E is accessible
- No enclosing instance of type Demo06 is accessible.
- No enclosing instance of type XXX is accessible
- No enclosing instance of the type RegisterActivity is accessible
- 报错:No enclosing instance of type ExtendsDemo is accessible.
- 黑马程序员——面向对象三大特征(封装、继承、多态)
- VS* 之VC 常见编译运行错误 积累
- fibonacci数列的性质(ZOJ3707)
- linux实用PF_PACKET接收原始链路层数据包
- log4cplus的一些问题
- No enclosing instance of type SearchCommand is available due to some intermediate constructor invoca
- java web strusts2 配置中的问题
- 特征选择常用算法综述
- Codeforces CROC problem C
- Oracle:外键关联导致数据无法删除
- 利用NFS服务挂载NFS根文件系统
- Android通过JNI调用驱动程序(完全解析实例)
- 使用Gnu gprof进行Linux平台下的程序分析
- 约瑟夫问题