Is java like “properties” in c#?

See English answers > does java have "properties" that work the same way properties work in c#? 5

I searched for Java properties like C # but so far only found one "hit" I'm not sure if it's an attribute or something else

Reading the java tutorial, I stumbled upon some text and code (* * emphasize and comment on my):

Finally,you can use the built-in **length property** to determine the
size of any array. The code:

 //notice lack of brackets after anArray.length :
 System.out.println(anArray.length);

will print the array's size to standard output.

Because array has a length attribute, Java does have an attribute, right?

Can anyone point out some documents about them?

Solution

It really depends on the definition you use Accessing data of certain classes without parentheses is a very weak definition of "properties" You can make any class / instance member field public so that you can access it without using methods

This will not make it like c# attribute. You can add custom logic and how to get and set it in this field! You can read / write variables directly The length field of an array is not writable and is actually immutable, so completing it is not a terrible style But other classes that expose their domain also have trouble, such as point and dimension

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>