A1 Yes it is possible, but requires you to type more and more.
While this is not certainly something essentially wrong, it is one of the things developer complain more about. They ( and sometimes I do my self ) feel that Java is too verbose.
As the hardware got faster, new programming languages which at the beginning were too expensive to perform computations became feasible, and they are now being used more and more and are very popular. When developers have to type in Java again they feel, like oh no:, public static void main
again! kind of.
One of the things that Java ( and statically types languages in general ) had to increase execution speed is to perform as many validations as possible before running ( that is, in the compiling stage )
These new programming languages ( remarkably Python and Ruby ) make a joy to program in, because you have to type less to achieve the same.
The reaction Java is taking to this, is to make the language bigger and incorporate some of this "syntactic sugar" into the language, that's why.
Even programming languages like C# had these extended features ( properties comes to my mind ) to make the developer code less.
At the end, I think these additions benefit the language, but they have to be added very carefully, to avoid break the compatibility and/or create a language that is so big, that nobody can use it.
I think an alternative would've been to allow the methods to be more expressive in their names, but that's very complicated, for Java. Perhaps in a new language :).
The Map put method signature could have been like this:
/**
* Analog to put( Object k, Object v );
*/
public [( Object = k )]=( Object v ) {
}
That's allow the method name be: [(key)]=(value)
and eventually omit the parenthesis ( like in Ruby or originally in Smalltalk ) so this method would be:
Map map = ....
map.["name"]="Oscar";
Since that's not possible ( because []=
are not valid method identifiers ) and writing:
map.put("name","Oscar");
Is ... mmhh too verbose, they decided to add this solution.
Another enhancement are number literals, so you will be able to type:
int million = 1_000_000;
A2 : You will get something else.
A3 ( expanding my comment on kloffy answer ).
You could write that same code in Java as of today.
Granted Stage, Scente, Group, Text, ImageView, Image
were existing Java classes, you could type:
new Stage() {{
title = "Group-Nodes-Transformation";
scene = new Scene() {{
width = 600;
height = 600;
content = new Group() {{
content = new Object[] = {
new Circle() {{
centerX = 300;
centerY = 300;
radius = 250;
fill = Color.WHITE;
stroke = Color.BLACK;
}},
new Text() {{
x = 300;
y = 300;
content = "Mr. Duke";
}},
new ImageView() {{
image = new Image() {{
url = "D:\\TEST\\Documents\\duke.png"
width = 50;
height = 50;
}};
}};
};
}};
}};
}};