java - .method() without reference -
i've noticed following code compiler in program:
arraylist<token> eval = new arraylist<>(0); (token token : tokens) { eval.add(token); if (token.equals(new token("eos", "eos"))) { .clear(); } else { continue; } }
but, part .clear()
confuses me. should doing instance.method()
, .method()
works too! why this?
the snippet in question syntactically incorrect. following syntax applies method invocation expressions
method invocation
- methodname ( [argumentlist] ) - typename . [typearguments] identifier ( [argumentlist] ) - expressionname . [typearguments] identifier ( [argumentlist] ) - primary . [typearguments] identifier ( [argumentlist] ) - super . [typearguments] identifier ( [argumentlist] ) - typename . super . [typearguments] identifier ( [argumentlist] )
in other words, can use identifier (name) of method, unqualified, context determine method , target reference (if has one). otherwise, you'll need expression or type name prefixes method identifier .
character. again, there set of rules determine method being invoked, @ compile time , run time.
this part of code
.clear();
does not fit syntax defined above. is, if used literally in source, syntactically incorrect in java.
you might looking @ pseudo code or abridged form of language (within ide, example).
Comments
Post a Comment