2017-04-22 8 views
2
package com.company; 

import java.lang.annotation.ElementType; 
import java.lang.annotation.Retention; 
import java.lang.annotation.RetentionPolicy; 
import java.lang.annotation.Target; 
import java.util.List; 

public class Main { 

    @Target(ElementType.TYPE_USE) 
    @Retention(RetentionPolicy.RUNTIME) 
    public @interface A {} 

    public static void main(String[] args) { 
    } 

    private List<@A Integer> integers1; 

    private List<@A java.lang.Integer> integers2; 
} 

を使用しているとき「記号を見つけることができません」スロー< @Aはjava.lang.Integer> integers2。 エラーを取得: エラー:(20、21)は、Javaを:クラスのjava 場所:シンボル シンボルを見つけることができないクラスcom.company.Main型注釈が プライベートリストに完全修飾タイプ

は、それはプログラムのバグですか?

+0

最近、私は完全に退屈していない注釈にいくつか変更を加えましたが、私は「プログラムのバグ」に投票します。ジェネリック型パラメータではアノテーションを使用できません。 – markspace

+1

プライベートリスト<@A Integer>整数1; は完璧です – user1222796

+1

これは:https://bugs.openjdk.java.net/browse/JDK-8074346? –

答えて

2

これは明らかに正常な動作(9.7.4)である。言い換えれば

A type annotation is admissible if both of the following are true:

  • The simple name to which the annotation is closest is classified as a TypeName, not a PackageName.

  • If the simple name to which the annotation is closest is followed by "." and another TypeName - that is, the annotation appears as @Foo T.U - then U denotes an inner class of T .

@Aは(java)に最も近い単純な名前がPackageNameあるので、注釈は許容できないで、コンパイラエラーが発生します。

修飾名の型名の正しい構文は[email protected] Integerです。

関連する問題