What is a JavaBean exactly?

后端 未结 19 1522
清酒与你
清酒与你 2020-11-22 01:55

I understood, I think, that a \"Bean\" is a Java class with properties and getters/setters. As much as I understand, it is the equivalent of a C struct. Is that true?

<
19条回答
  •  有刺的猬
    2020-11-22 02:22

    As per the Wikipedia:

    1. The class must have a public default constructor (with no arguments). This allows easy instantiation within editing and activation frameworks.

    2. The class properties must be accessible using get, set, is (can be used for boolean properties instead of get), and other methods (so-called accessor methods and mutator methods) according to a standard naming convention. This allows easy automated inspection and updating of bean state within frameworks, many of which include custom editors for various types of properties. Setters can have one or more than one argument.

    3. The class should be serializable. [This allows applications and frameworks to reliably save, store, and restore the bean's state in a manner independent of the VM and of the platform.]

    For more information follow this link.

提交回复
热议问题