views:

49

answers:

1

I have set up an annotation that will be used to keep track of classes, however I am getting an error when I try to compile any java code that uses the annotation.

Here is the annotation code:

package tlib.anno;

import java.lang.annotation.*;

@Retention( RetentionPolicy.RUNTIME )
@Target( ElementType.TYPE )

public @interface Class
{
    String author();
    String contact();
    String creationDate();
    String creationTime();

    String lastUpdateDate();
    String lastUpdateTime();

    int version() default 1;
    int majorVersion() default 0;
    int minorVersion() default 0;
    int build() default 1;
}

Then when I try to use the annotation like so:

import tlib.anno.Class;

...

@Class( author = "tjlevine",
    creationDate = "2/18/09",
    creationTime = "11:20:16 PM",
    lastUpdateDate = "2/18/09",
    lastUpdateTime = "11:27 PM",
    version = 1,
    majorVersion = 1,
    minorVersion = 0 )
public class Vector2d implements Cloneable
{
    ...
}

The compiler gives me this error:

/media/disk/programming/java/tLib/src/tlib/math/Vector2d.java:13: annotation tlib.anno.Class is missing contact

Google is of little help with this error, and I can't figure out what it is telling me.

+3  A: 

Change it to:

public @interface Class {
  String author() default "";
  String contact() default "";
  String creationDate() default "";
  String creationTime() default "";

  String lastUpdateDate() default "";
  String lastUpdateTime() default "";

  int version() default 1;
  int majorVersion() default 0;
  int minorVersion() default 0;
  int build() default 1;
}

Basically the compiler is complaining because the way you've defined it, contact is required and you haven't specified it.

Of course you may not want to make all of these attributes optional. Just don't specify a default value for any that are required.

cletus
Thanks so much, feeling dumb now, haha
tjlevine