I'm examining a source code written by someone else. I've encountered something like this:
x = new MyObject();
x._("somestring")
What does this expression object._("a string here") mean?
It simply means you have a method whose name is _
in the class MyObject
(or a superclass). There's nothing special, the _
character just happens to be valid in Java names.
You might be surprised because you don't see that often. And you don't see that often because "this practice is discouraged". It makes the code harder to read.
See here :
A variable's name can be any legal identifier — an unlimited-length sequence of Unicode letters and digits, beginning with a letter, the dollar sign "$", or the underscore character "_". The convention, however, is to always begin your variable names with a letter, not "$" or "_". Additionally, the dollar sign character, by convention, is never used at all. You may find some situations where auto-generated names will contain the dollar sign, but your variable names should always avoid using it. A similar convention exists for the underscore character; while it's technically legal to begin your variable's name with "_", this practice is discouraged. White space is not permitted
Class MyObject
has a method _() which accept String
as input argument.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With