将内部类作为Java静态的优势是什么? [英] What's the advantage of making an inner class as static with Java?

查看:111
本文介绍了将内部类作为Java静态的优势是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的Java类中有一个内部类。

I have an inner class in my Java class.

当我运行查找错误,它建议(警告)将其设置为静态。

When I run find bugs, it recommends(warns) to make it as static.

>

这个警告的意义是什么?将内部类作为静态变量的优点是什么?

What's the point of this warning? What's the advantage of making a inner class as static?

推荐答案

如果嵌套类不访问任何变量类,它可以被静态。这样做的优点是,您不需要使用嵌套类的外部类的封闭实例。

If the nested class does not access any of the variables of the enclosing class, it can be made static. The advantage of this is that you do not need an enclosing instance of the outer class to use the nested class.

这篇关于将内部类作为Java静态的优势是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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