JSR 308
December 12, 2013 Leave a comment
The annotation system has been extended. I realized that there are more annotation types and more source locations where they are permitted.
I compiled a simple example. The specification is here
java version "1.8.0-ea"
Java(TM) SE Runtime Environment (build 1.8.0-ea-b113)
Java HotSpot(TM) 64-Bit Server VM (build 25.0-b55, mixed mode)
package com.test; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; public class Test { @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.TYPE_USE) @interface TypeUse {} @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.TYPE_PARAMETER) @interface TypeParameter {} @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.TYPE_PARAMETER) @interface TestTypeParameter {} @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.PARAMETER) @interface NonNull {} /** * ElementType.TYPE PARAMETER stands for a type parameter — that is, the declaration of a type variable. Examples are in generic class declarations class MyClass<T> {...}, generic method declarations <T> foo(...) {...}, and wildcards List<?>, which declare an anonymous type variable. * @param <T> */ @TypeUse class Test1<@TypeParameter @TestTypeParameter T extends @TypeUse Integer> { /** * A type annotation is permitted in front of a constructor declaration, where declaration annotations are already permitted. */ @TypeUse <@TypeParameter @TestTypeParameter S> Test1(String s){ } } public static void main( @NonNull String... argv ){ Object o = ( @TypeUse String ) new String( "Test" ); if( o instanceof @TypeUse String ){ } try{ }catch( @NonNull Exception e){ } } }
List list1 = list. stream(). map(p::matcher). filter(Matcher::find).map(matcher -> matcher.group()). collect(Collectors.toCollection(@ NonNull ArrayList::new));