I have the following abstract Java class:
abstract class AbstractDto {
String id;
public void setId(String id) { this.id = id; }
public String getId() {return id; }
}
I also have class which extends the abstract class:
class SomeDto extends AbstractDto {
@SomeAnnotation
String id;
}
I want to annotate an instance variable derived from an abstract class. I am not sure if this is the way to go as I did it. I know that Java does not provide variable overloading so this is shadowing.
So what happens if I do:
public void go(AbstractDto dto) {
println("dto.id: "+dto.id);
}
AbstractDto dto = new SomeDto();
dto.setId("1234");
go(dto);
Since I do shadowing when I set the id of SomeDto then there is an id
variable inherited from AbstractDto which is still not set.
How can I annotate an instance variable defined in an abstract super class?
Edit: When I do:
SomeDto dto = new SomeDto();
dto.setId("123");
Which id was set the one in AbstractDto or the one in SomeDto? What happens I a method in the Abstract class reads from id which id is then used?