Creating an anonymous instance of an annotation does not work

12 views
Skip to first unread message

Thomas Driessen

unread,
Apr 26, 2017, 7:12:47 AM4/26/17
to Xtend Programming Language
Hi again,

I'm still playing around with Java annotations in Xtend and stumbled upon the next issue.

I'm trying to create an anomymous instance of my annotation like this:


annotation MyConfiguration{
String name = 'osgi'
}

class InstanceTest{

    def doSomething(){
        
        var MyConfiguration config = new MyConfiguration(){
             
             override annotationType(){
                 null
             }

             override name(){
                 null
             }
        }
    }
}

where Xtend complains about not being able to resolve MyConfiguration, although I imported it.

In plain Java everything works fine:


public @interface MyConfiguration {
  public String name() default "osgi";
}


public class InstanceTest{
  
  public MyConfiguration doSomething() {
 MyConfiguration config = new MyConfiguration() {
@Override
public Class<? extends Annotation> annotationType() {
return null;
}
@Override
public String name() {
return null;
}
};
  }
}

Kind regards,
Thomas

Christian Dietrich

unread,
Apr 27, 2017, 4:53:49 AM4/27/17
to Xtend Programming Language
hmmm i dont know what this java feature is good for.
anyway can you please file a ticket at
https://github.com/eclipse/xtext-xtend

Thomas Driessen

unread,
Apr 28, 2017, 8:25:23 AM4/28/17
to Xtend Programming Language
It can be used for typesafe configuration of services in OSGi... at least I think so ;)
Reply all
Reply to author
Forward
0 new messages