Annotation attribute must be a class literal? Why? Constants should be fine too

后端 未结 5 810
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-02-13 18:55

Can someone explain why String and Class annotation parameters are expected differently? Why does the compiler require literals for Classes, wherby accepting constants for Strin

5条回答
  •  我在风中等你
    2021-02-13 19:16

    I got the "annotation value must be a class literal" on the following:

    @ServerEndpoint(value="/story/notifications",
            encoders = (StickerEncoder.class),
            decoders = (StickerDecoder.class))
    

    This happening whilst following one of Oracles tutorials on websockets. Turns out the video is not the 720p quality and the fuzziness hides the braces which look like curly brackets. So the error disappears upon changing brackets (parentheses) for braces.

    @ServerEndpoint(value="/story/notifications",
            encoders = {StickerEncoder.class},
            decoders = {StickerDecoder.class})
    

    hth anyone who may trip over the same in the future.

提交回复
热议问题