I really like the annotation
@Data. Unfortunately if you try to build an entity relationship model with a lot of classes referencing each other, you'll get entangled with the generated
hashCode(),
equals() and
toString() methods.
This comes down to bear and result in a
StackOverflowException, if you'll use JPA.
Therefore I propose the following annotation:
@Target(value=FIELD) @Retention(value=SOURCE)
public interface @Proxy{
String method();
String field();
String onObjectMethod();
String onObjectField();
}
Declaring this annotation on a field (
User user) with
method="getUserId" will force
hashCode(),
equals() and
toString()to use the return value of the method
getUserId()instead of this fields value
. The method
getUserId()has to be declared in the class of the annotated field.
Declaring this annotation on a field (
User user) with
field="userId" will force
hashCode(),
equals() and
toString()to use the value of the field u
serId instead of this fields value
. The field
userId has to be declared in the class of the annotated field.
Declaring this annotation on a field (
User user) with
onObjectMethod="getId" will force
hashCode(),
equals() and
toString()to use the return value of the method
getId()of
User instead of this fields value
. The method
getUserId()has to be declared in the class of the type of the annotated field.
Declaring this annotation on a field (
User user) with
onObjectField="id" will force
hashCode(),
equals() and
toString()to use the value of the field
id of
User instead of this fields value
. The field
id has to be declared in the class of the type of the annotated field.
Other names for this annotation could be
@Relegate,
@Delegate,
@Indicate, etc. .