ACDK Guide-CDK Foundation

xiaoxiao2021-03-06  39

ACDK Guide-CDK Foundation

Translation: Xue Changyu We will introduce you to the ACDK foundation.

This chapter: Establish an object Access Method Access Field Release Object Replication Reference Replication Instance Parameter and Return Value

Establish an object to create a new object using 'new'. Save this new object to a reference. A type of reference to an object is the name of the R class, such as the type of StringBuffer is RStringBuffer.

{RStringBuffer SB = new stringbuffer ();

The access method is different from Java, which is different for static or dynamic approaches.

{RStringBuffer SB = New StringBuffer (); SB-> Append ("hi"); // Non static call rstring str = string :: valueof (3.4); // static cal}

Accepted fields In general, the fields of access to the class are not directly accessed by the SET / GET method.

Release the object object is released. If the final pointing to the reference to this object disappears, they will be automatically released. As a choice, you can also directly assign the NIL value to this reference:

{RStringBuffer SB1 = New StringBuffer ("m"); SB1-> Append ("ja"); SB1 = NIL; // SB1 no longer saved StringBuffer, StringBuffer will be removed}

Copy reference If you want to copy a reference, you can easily do this:

{RStringBuffer SB1 = New StringBuffer ("m"); RStringBuffer SB2 = SB1; // SB2 will contain the same StringBuffer instance SB2-> Append ("a"); SB1-> Append ("ja"); // StringBuffer Because the content is "maja" ("ACDK" in the original text, but I think it is the author's incorrectly)}

See: Quote.

Copy Example In ACDK, you can copy an instance (not just reference) {RStringBuffer SB1 = New StringBuffer ("m"); rstringbuffer sb2 = sb1-> clone (); // SB2 contains a replica SB2-> Append "A"); SB1-> Append ("ja"); // SB2 content "ma" // SB1 content "aja"}

The parameters and return values ​​are default, only the parameters or return values ​​that can be used as the method can be referenced. Similar to rules in Java.

Rinteger myparse (RStringBuffer arg) {rtring str = arg-> toString (); rinteger Erg = INTEGER :: PARSEINT (STR); Return Erg;}

// The same, but more 'inlined' version of Rinteger myparse (RStringBuffer Arg) {Return Integer :: PARSEINT (Arg-> toString ());

转载请注明原文地址:https://www.9cbs.com/read-74669.html

New Post(0)