Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add Java Annotation to inherited field

I'm working on something that might benefit from a pattern like the following:

public abstract class SomeBuisnessThingy()
{
  protected int someDatapoint;
}

public class ADatabaseThingy() extends SomeBusinessThingy()
{
  @SomeJPAAnnotation
  ???? someDatapoint;
}

public class AWebServiceThingy() extends SomeBusinessThingy()
{
  @SomeSOAPStuff
  ???? someDatapoint;
}

It smells more like an interface than an abstract class, but the same thing needs to be done. I have a DB implementation of that class and a WS implementation of that class.

Those representations are very similar, but may be different. For example the WS class may expose a field as a String so a 3rd party can easily do an integration, it can also be splot into its own package so we can hand a customer some lightweight WebService or POJO classes without all the baggage of the DB or a JPA framework coming with it. Perhaps it could be used to create the basic classes needed for something then switch between persistence frameworks that use different annotations.

Is it possible to ADD annotations to inherited fields?

like image 848
Freiheit Avatar asked Jan 11 '10 22:01

Freiheit


1 Answers

No. If you need to annotate inherited members, you need to annotate the methods, not the fields.

like image 197
skaffman Avatar answered Oct 03 '22 21:10

skaffman