JSR 308

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));

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s

%d bloggers like this: