[bv-dev] Talk "Annotations and Annotation Processing: What’s New in JDK 8?"
Hardy Ferentschik
hardy at hibernate.org
Thu Nov 22 05:54:56 EST 2012
On 21 Jan 2012, at 10:53 PM, Gunnar Morling <gunnar at hibernate.org> wrote:
> 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!
Right, we are waiting for this for a looooong time now :-)
See:
- https://hibernate.onjira.com/browse/HV-296
- https://hibernate.onjira.com/browse/BVAL-202
> * 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.
Nice, but BV basically has this feature already :-) Just means more work for us catering for this case as well
> * 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
I never really warmed to the TypeElement API and the visitor pattern one has to use in an annotation processor, but it makes
sense to unify this and if it helps to solves problems like determine whether one method overrides another it would close a big hole
in the current reflection API.
IMO it takes ways to long to bring some enhancements to annotations and reflection. These issues should have been addressed
latest for JDK 7.
> So it seems there is a BV 1.2 due once JDK 8 is through the door :)
:-)
--Hardy
More information about the beanvalidation-dev
mailing list