[bv-dev] Talk "Annotations and Annotation Processing: What’s New in JDK 8?"

Gunnar Morling gunnar at hibernate.org
Wed Nov 21 16:53:44 EST 2012


Hi all,

At J1 there was an interesting talk on what's new in JDK 8 regarding
annotations [1]. There are some things which are beneficial for the Bean
Validation use case:

* JSR 308 (annotations on types): Will allow us to do things like
private List<@Email String> emails;

Yeah!

* Repeating annotations: One can put the same annotation several times to
an element:

@Size(min=8, groups=Default.class)
@Size(min=16, groups=Admin.class)
private String password;

The compiler puts that into a container annotation (e.g. @Size.List) and
there will be updates to the reflection API to retrieve repeated
annotations.

* javax.lang.model backed by Core Reflection:

The model API will be usable at runtime, taking reflection types as input:

TypeElement someClassElement = createMirror(SomeClass.class);

So this will allow to share code between a Bean Validation runtime (which
typically uses reflection) and an annotation processor (which typically
uses the model API) for checking constraints etc.

Hardy, as a bonus, this will make it finally dead easy to discover
overridden methods :) :

ExecutableElement superFoo =
createMirror(Super.class.getDeclaredMethod("foo"));
ExecutableElement childFoo =
createMirror(Child.class.getDeclaredMethod("foo"));
TypeElement childElement = createMirror(Child.class);

assert getElements().overrides(childFoo, superFoo, childElement) == true

So it seems there is a BV 1.2 due once JDK 8 is through the door :)

--Gunnar

[1]
https://oracleus.activeevents.com/connect/sessionDetail.ww?SESSION_ID=4469
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/beanvalidation-dev/attachments/20121121/b0abcb96/attachment.html 


More information about the beanvalidation-dev mailing list