[JSR308] Custom annotations?

Richard Gomes rgomes1997 at yahoo.co.uk
Sat Feb 2 22:44:39 EST 2008


Hi All,

I was able to get JSR-308 annotation checkers working fine.
The test program below uses @NonNull to make sure the environment is correctly 
set. The test is intended to exercise if we can detect the wrong use of 
Double variables which have different semantics.

My question is: how can I turn on type checkings relative to the annotations 
@Rate and @Volatility I've defined?

Thanks in advance.


=== Main.java ==============================
import checkers.quals.NonNull;

public class Main {

	private void calculate(@Rate Double rate, @Volatility Double vol) {
		System.out.println(Math.pow(vol, rate));
	}

	private void allTests() {
		@Rate Double       rate = 0.45;
		@Volatility Double vol  = 0.5;

		@NonNull Double d = null; // Yeah! I've got a compiler error! :)
		
		calculate(rate, vol); // Pass
		calculate(vol, rate); // Should give a compile error   <<<< =====
	}
	
	public static void main(String[] args) {
		Main test = new Main();
		test.allTests(); // Why I've got (defer.invalid) here??? <<<< =====
	}
}

=== Rate.java ==============================

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;


@Retention(RetentionPolicy.RUNTIME)
@Target({ ElementType.FIELD, ElementType.LOCAL_VARIABLE, 
ElementType.PARAMETER })
public @interface Rate {
	// No methods - Tagging annotation
}

=== Volatility.java ==============================

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;


@Retention(RetentionPolicy.RUNTIME)
@Target({ ElementType.FIELD, ElementType.LOCAL_VARIABLE, 
ElementType.PARAMETER })
public @interface Volatility {
	// No methods - Tagging annotation
}

=================================

-- 
Richard Gomes
http://www.linkedin.com/in/rgomes
M: +44(77)9955-6813
H: +44(870)068-8205
sip:200200 at jquantlib.org
<a href="http://www.voip-info.org/wiki/view/What+is+VOIP">What is VoIP?</a>

See my project on Quantitative Finance
http://www.jquantlib.org/



More information about the JSR308 mailing list