由于一些中间构造函数调用,没有 PerfHelper 类型的封闭实例可用 [英] No enclosing instance of type PerfHelper is available due to some intermediate constructor invocation

查看:20
本文介绍了由于一些中间构造函数调用,没有 PerfHelper 类型的封闭实例可用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

考虑以下代码:

class abstract Normal1 extends Something 
{
}

class Outer 
{
  class abstract Inner extends Normal1
  {

  }
}

class General extends Outer.Inner  // Problem occurs at this 
{
}

我得到的错误是由于某些中间构造函数调用,没有可用的 PerfHelper 类型的封闭实例"

The error I am getting is "No enclosing instance of type PerfHelper is available due to some intermediate constructor invocation"

我的问题是我可以像上面那样扩展内部类吗?

My question is can I extend the inner class like above ?

推荐答案

将内部类声明为 static 并且您应该能够扩展它:

Declare the inner class as static and you should be able to extend it:

class outer {
  static abstract class inner extends normal1 { }
}

如果inner不是抽象的,它和outer绑定,并且只有在outer的实例存在时才能存在.检查这是否是您真正想要的.

If inner is not abstract, it's tied to outer, and can only exist when an instance of outer exists. Check to see if this is what you really want.

这篇关于由于一些中间构造函数调用,没有 PerfHelper 类型的封闭实例可用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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