Accessing a Field
←Older revision | Revision as of 13:44, 27 February 2013 | ||
Line 37: | Line 37: | ||
</source> | </source> | ||
- | === Accessing | + | === Accessing an Instance Field === |
To support subclasses defining the same field (like in case of [http://source.apidesign.org/hg/bck2brwsr/rev/5e13b1ac2886 InheritanceA and InheritanceB classes]) the [[Bck2Brwsr]] needed to create accessor method to access each field in its declaring class. The accessor which prefixes the name of the field with "_" (forming a name that can't clash with mangled method names). The proper way to access field ''value'' defined in String class would then be: | To support subclasses defining the same field (like in case of [http://source.apidesign.org/hg/bck2brwsr/rev/5e13b1ac2886 InheritanceA and InheritanceB classes]) the [[Bck2Brwsr]] needed to create accessor method to access each field in its declaring class. The accessor which prefixes the name of the field with "_" (forming a name that can't clash with mangled method names). The proper way to access field ''value'' defined in String class would then be: | ||
Line 56: | Line 56: | ||
which does the same in most cases. Only when there is a subclass defining its own field ''value'', the result would not be correct. Thus this kind of usage is appropriate when one knows the class is final and can't be subclassed (another reason to follow the [[ClientAPI]] advice). | which does the same in most cases. Only when there is a subclass defining its own field ''value'', the result would not be correct. Thus this kind of usage is appropriate when one knows the class is final and can't be subclassed (another reason to follow the [[ClientAPI]] advice). | ||
+ | |||
+ | === Accessing a Static Field === | ||
+ | |||
+ | Static fields are wrapped by accessors as well. However accessing them is simpler as they don't need proper '''this''' argument. One can use: | ||
+ | |||
+ | <source lang="javascript"> | ||
+ | var getValue = vm.java_lang_String(true)._CASE_INSENSITIVE_ORDER(); | ||
+ | var newValue = "..."; | ||
+ | vm.java_lang_String(true)._CASE_INSENSITIVE_ORDER(newValue); | ||
+ | </source> | ||
== Possible Future Work == | == Possible Future Work == |