Retreiving Object with specific annotation

36 views
Skip to first unread message

Roger Gilliar

unread,
May 25, 2012, 4:35:27 AM5/25/12
to google...@googlegroups.com
Is it possible to retrieve an object with a specific annotation.

Example:

@ExtensionId(value=123)
class Test {
}

@ExtensionId(value=124)
class Test2 {
}

Object obj = injector.getInstance(???); // retrieve the object with the  @ExtensionId(value=123)
Object obj = injector.getInstance(???); // retrieve the object with the  @ExtensionId(value=124)

That would allow me to use the extension-id in an Eclipse RCP app to retrieve a specifc UI object in a Factory class.

Regards
  Roger

Regards
  Roger


Thomas Broyer

unread,
May 25, 2012, 9:09:32 AM5/25/12
to google...@googlegroups.com
1. create a class (say ExtensionIdImpl) that implements the ExtensionId interface (have a look at Names.named() source code in Guice); make sure you follow the contract for Annotation#equals()
2. use injector.getInstance(Key.get(Test.class, new ExtensionIdImpl(123)));
Reply all
Reply to author
Forward
0 new messages