为什么JavaBean功能没有内置到根JAVA对象中? [英] Why aren't javabean features built into the root JAVA object?

查看:77
本文介绍了为什么JavaBean功能没有内置到根JAVA对象中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很难理解为什么必须要有javabeans,为什么它们不只是将javabean功能直接放入Java中的对象类(根类)中?

I'm having a hard time understanding why javabeans are necessary and why they didn't just place the javabean features directly into the object class(root class) in java?

我的理解是,您将一个对象(实例)转换为Java Bean,这样您就可以为Bean中的所有对象获得诸如可序列化之类的所有好处。但是如果是这样,为什么还要为此使用一个单独的Bean类,为什么不只是将其内置到根对象类中呢?

My understanding is you turn an object(instance) into a java bean and that way you get all the benefits like serializable and so on for all the objects in the bean. But if that is the case, why even have a separate bean class for this, why not just have built into the root object class?

还是我不明白这一点?

Or am I not understand this?

推荐答案

您对它的理解不正确。
没有实际的Java类或接口是bean。

You are not understanding it correctly. There is no actual Java class or interface that is a bean. It is merely a pattern, a convention.

bean约定基本上是一个类将通过公共getXxx和setXxx方法公开其某些或所有属性,其中XXX是属性的名称。

The bean convention is basically that a class will publicly expose some or all of its properties via public getXxx and setXxx methods, where XXX is the name of the property.

Bean通常应该可序列化,但是任何类都可以序列化,并且不需要遵循Bean约定。

Beans generally should be serializable, but any class can be serializable, and does not need to follow the bean convention.

这篇关于为什么JavaBean功能没有内置到根JAVA对象中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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