This page is no longer maintained — Please continue to the home page at

Annotations on fields

No replies
Joined: 2010-01-14,
User offline. Last seen 2 years 38 weeks ago.


I'm writing a circuit simulation program in Scala and I got stuck...

I have a Java annotation:

@Target({ElementType.METHOD, ElementType.FIELD} )
public @interface ModelEquation {

And then I'm trying to use it on the val or def.

case class Resistor(id: Id, resistance: Expression[DoubleWithError])
extends ReflectiveModel {

val t1 = Terminal(id.subId("1"))
val t2 = Terminal(id.subId("2"))

val eq1 = t1.current * resistance + t1.voltage - t2.voltage

val eq2 = t1.current + t2.current

Now I want to read at runtime which equations are given by this model:

val methods =

I get an empty list. When I change those fields from vals to defs, it
works, giving the annotated methods. What happens to the annotation on a
val field? Where can I find it at runtime? I want to make my
@ModelEquation annotation work for both defs and vals.

Piotr Kołaczkowski

Copyright © 2012 École Polytechnique Fédérale de Lausanne (EPFL), Lausanne, Switzerland