Java 8 TYPE_USE annotations not behaving if array is annotated inside List or Map

后端 未结 2 1202
失恋的感觉
失恋的感觉 2021-01-16 05:16

I\'m trying to write a simple validation lib with annotations that use the new TYPE_USE target from Java 8. The way to access these things is really complex, and left me wit

2条回答
  •  轮回少年
    2021-01-16 06:05

    You said:

    @First("array") List<@First("string") String> @First("list") [] arrayOfListOfString;
    

    Works fine (the annotations are matched with the corresponding types).

    This looks wrong to me. A type such as

    @English String @NonEmpty []
    

    is read as "non-empty array of English strings".

    Now let's consider your example (which I have simplified slightly):

    @First("array") List @First("list") [] arrayOfList;
    

    You have a @First("list") array, where each element is a @First("array") List. Is that what you want? It's not what is implied by the names.

    I don't know what is wrong with your code in the listOfArrayOfInteger case, but you might want to revisit your claim "The code seems to work in every other scenario" given that the one example that you gave seems to be incorrect.

提交回复
热议问题