I know Java doesn't support operator overloading, but it seems there are a few operators in other languages that could potentially benefit Java.
Probably my favorite example is the .?
operator. Members of an object are only accessed using .?
if the object is non-null:
public void example(String arg)
{
if(arg != null && arg.equals("quit"))
...
}
Could be shortened to
public void example(String arg)
{
if(arg.?equals("quit"))
...
}
The .?
operator is (at least imho) easy to read, and eliminates some extra code that can sometimes be a detriment to code readability. In some code, there may be multiple checks on the null-state of an object or parameter, and may lead to unnecessary and excessive indentation on entire blocks of code.
Obviously, this would be no revolutionary change, but .?
could be universally applied to all subclasses of Object
as far as I can see. Am I wrong? And would this go against the logic used to decide that Java won't support operator overloading if it were to be adopted now?