gpt4 book ai didi

java - 为什么无参数构造函数会在无效状态下被实例化?

转载 作者:行者123 更新时间:2023-11-30 08:20:48 24 4
gpt4 key购买 nike

我一直在寻找 JavaBean 的优点和缺点。在缺点部分,我遇到了这个:

一个带有 nullary constructor 的类可能会在无效状态下被实例化。 Wikipedia - JavaBeans

这到底是什么意思?这如何反对具有参数参数的构造函数?

最佳答案

If such a class is instantiated manually by a developer (rather than automatically by some kind of framework), the developer might not realize that the class has been improperly instantiated.

JavaBean 框架可以对实例化的 JavaBean 执行自动操作,例如,通过调用方法、将参数传递给常规方法等,这取决于 JavaBean 的设计目的,以及框架预期如何处理 JavaBean它的控制。

The compiler can’t detect such a problem, and even if it’s documented, there’s no guarantee that the developer will see the documentation.

换句话说:“开发人员并不总是勤奋,即使勤奋,他们也不总是正确的。”

专门为自动化工具使用而设计的组件并不总是为实际人员使用而设计的。

关于java - 为什么无参数构造函数会在无效状态下被实例化?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25692933/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com