Skip to main content

Would you like to see UML-like access specifiers in java 7?

1 reply [Last post]
Joined: 2009-02-11

Here is example:
class Point {
- int x;
- int y;
+ Point(int x, int y) {
this.x = x;
this.y = y;
I think it is more concise, isn't it?
I believe, C-like syntax success (C++, Java, C#, JavaScript and couple of other langs) is a result of its conciseness.when keywords don't shadow application content.

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Joined: 2009-03-02

It is undoubtedly more concise, but other than UML, there's no precedent for it -- it's not apparent, either from past experience or self-evidence, that - means private and + means public.

Even worse, - and + are usually considered opposite values, of which there's no ambiguity in between. Package-private and protected values would have to be also represented, which further complicates the simple syntax you're going for.

I for one don't have too much of a problem typing private ;) Plus, it's usually on its own line, so I'm usually not worried about space concerns.

If I was looking for things to make more concise, I'd pick on some of these:

- BigDecimal not masquerading as a number
- Type-parameter redundancy: List stringList = new ArrayList()
- Indexed-value access through []'s: stringList[2] = "foo";
- Properties ( stringList.size instead of stringList.getSize()

For me personally, though, I don't mind the current state of things as far as conciseness goes. I think adding syntactic sugar to a language must be done with care (Like the enhanced for-loop), lest you unnecessarily complicate either the language or the readability, for the sake of saving keystrokes.