[ovirt-devel] Diamonds are a (Java) developer's best friends

Allon Mureinik amureini at redhat.com
Tue Dec 1 13:04:37 UTC 2015


Hi team,

Back in the day, somewhere between the discovery of fire and the wheel,
Java 5 introduced generics. This was a great step forwards, but also
created some of the most horrible boiler-plated code you could imagine:

    Map<Guid, List<Preson<Guid>> = new HashMap<Guid, List<Preson<Guid>>();

Java 7 improved the situation by adding generic type inference, a.k.a the
diamond operator [1]:

    Map<Guid, List<Preson<Guid>> = new HashMap<>();

This style is defacto the standard of the engine, with new patches using it
and patches to fix old code that doesn't use it being accepted pretty
quickly.

Since we defacto agreed on this standard, I'd like to put my money where my
mouth is, and make it a declarative standard.
I have a series of patches [2] that fix **all** the occurrences of
non-diamond declarations [3][4][5] (well, except for anonymous
implementations like we have in the DAOs) and adds a checkstyle validation
[6] to prevent further declarations like this from entering the project in
the future.

Engine maintainers, please review and assist in getting this series merged.
The rebase will be hellacious as it is, and I'd like to minimize the effort
as much as possible.


Thanks,
Allon


[1]
http://docs.oracle.com/javase/7/docs/technotes/guides/language/type-inference-generic-instance-creation.html
[2]
https://gerrit.ovirt.org/#/q/status:open+project:ovirt-engine+branch:master+topic:diamond
[3] https://gerrit.ovirt.org/49490
[4] https://gerrit.ovirt.org/49491
[5] https://gerrit.ovirt.org/49492
[6] https://gerrit.ovirt.org/49493
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ovirt.org/pipermail/devel/attachments/20151201/869158a2/attachment-0001.html>


More information about the Devel mailing list