No, there isn’t really. Nashorn (well, actually Dynalink that’s underlying Nashorn’s Java-binding functionality) gives preference to a method over a field as methods are more flexible, can include preconditions, can be overridden etc. There’s an assumption that whoever designs the class with both a field and a method sharing their name (or method name conforming to getter convention for the property) would consider the method to be more specific.
Attila. > On 2018. Jan 19., at 10:31, Nathan Faulkner <natedogi...@gmail.com> wrote: > > Is there any way, other than reflection, to access a field that shares a > name with a method? It seems that, with the Test class, instance.item > returns the item() dynamic method (as does instance["item"]), and > instance.item2 returns "b". > > public class Test { > public String item = "1"; > public String item2 = "2"; > > public String item() { > return "a"; > } > > public String getItem2() { > return "b"; > } > } > > > Thanks, > Nathan Faulkner