Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse 4 » Passing final static variables to @Named annotation not possible?
Passing final static variables to @Named annotation not possible? [message #990482] Wed, 12 December 2012 16:27 Go to next message
Alex Kipling is currently offline Alex KiplingFriend
Messages: 260
Registered: July 2012
Senior Member
I am trying to pass a constant to the @Named annotation.
The compiler tells me "The value for annotation attribute Named.value must be a constant expression"

Is it a bug of a compiler or is it intended to be impossible?


    static final String test = "test";
    @Inject
    private void monitorSlideName(@Named(test) String name) {
...
Re: Passing final static variables to @Named annotation not possible? [message #990483 is a reply to message #990482] Wed, 12 December 2012 16:29 Go to previous messageGo to next message
Alex Kipling is currently offline Alex KiplingFriend
Messages: 260
Registered: July 2012
Senior Member
Sorry, forgot to save - it works
Re: Passing final static variables to @Named annotation not possible? [message #990486 is a reply to message #990483] Wed, 12 December 2012 16:35 Go to previous messageGo to next message
Eclipse UserFriend
This is how you get your selection: IServiceConstans.ActiveSelection so it should work Wink
Re: Passing final static variables to @Named annotation not possible? [message #990604 is a reply to message #990486] Thu, 13 December 2012 11:59 Go to previous messageGo to next message
Alex Kipling is currently offline Alex KiplingFriend
Messages: 260
Registered: July 2012
Senior Member
Update:
Surprisingly it does not work, when the @Named parameter is retrieved from the classname.
Do you have an Idea why?

    private final static String test = Part.class.getSimpleName(); // error: The value for
                                                                   // annotation attribute
                                                                   // Named.value must be a constant
                                                                   // expression
    private final static String test2 = "Part"; // works

    @Optional
    @Inject
    private void monitorSlideName(@Active @Named(test) String name) {
Re: Passing final static variables to @Named annotation not possible? [message #990664 is a reply to message #990604] Thu, 13 December 2012 12:33 Go to previous message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
Yes that is expected, the value you have here is NOT a compile time
constant because it is derived from an expression. The compiler doesn't
know that the return of is a already defined at compile time because it
only sees a method call.

You can only use values the compiler can INLINE when doing the compilation.

Tom

Am 13.12.12 12:59, schrieb Alex Kipling:
> Update:
> Surprisingly it does not work, when the @Named parameter is retrieved
> from the classname.
> Do you have an Idea why?
>
>
> private final static String test = Part.class.getSimpleName(); //
> error: The value for
> //
> annotation attribute
> //
> Named.value must be a constant
> //
> expression
> private final static String test2 = "Part"; // works
>
> @Optional
> @Inject
> private void monitorSlideName(@Active @Named(test) String name) {
>
Previous Topic:How to listen for an activation of a successor IEclipseContext?
Next Topic:Redo/Undo Typing is not working properly for XML Files
Goto Forum:
  


Current Time: Tue Apr 23 16:23:07 GMT 2024

Powered by FUDForum. Page generated in 0.02988 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top