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 Kipling
Messages: 257
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 Kipling
Messages: 257
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
Sopot Cela is currently offline Sopot Cela
Messages: 597
Registered: December 2010
Senior Member

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 Kipling
Messages: 257
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 Schindl
Messages: 5400
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 Oct 21 03:49:50 GMT 2014

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

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