内部类是否常用于Java?他们是“坏”吗? [英] Are inner classes commonly used in Java? Are they "bad"?

查看:87
本文介绍了内部类是否常用于Java?他们是“坏”吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Java中常用的内部类是什么?这些是否与嵌套类相同?或者用Java更换这些更好的东西?我有一本关于版本5的书,它有一个使用内部类的例子,但我想我读过一些内部类是糟糕的。

Are inner classes commonly used in Java? Are these the same as nested classes? Or have these been replaced in Java by something better? I have a book on version 5 and it has an example using an inner class, but I thought I read somewere that inner classes were "bad."

我不知道并且希望对它有所了解。

I have no idea and was hoping for thoughts on it.

谢谢。

推荐答案

经常使用内部类,并且非常相似的东西 - 匿名类 - 实际上是不可或缺的,因为它们是Java最接近闭包的东西。所以,如果你不记得你听到内部课程不好的地方,那就别忘了!

Inner classes are frequently used, and something very similar - anonymous classes - are practically indispensable, as they are the closest thing Java has to closures. So if you can't remember where you heard that inner classes are bad, try to forget about it!

这篇关于内部类是否常用于Java?他们是“坏”吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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