我仍然不清楚Java中注释的目的。最初,我认为它们只是用作文档。但是查看Google App Engine Datastore的文档后,我不太确定了。 @PersistenceCapable(identityType = IdentityType.APPLICATION) 看起来更像一个方法签名。
这种类型的注释有什么目的?它是做什么用的?
这种类型的注释有什么目的?它是做什么用的?
import java.util.Date;
import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.IdentityType;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;
@PersistenceCapable(identityType = IdentityType.APPLICATION)
public class Employee {
@PrimaryKey
@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
private Long id;
@Persistent
private String firstName;
@Persistent
private String lastName;
@Persistent
private Date hireDate;
public Employee(String firstName, String lastName, Date hireDate) {
this.firstName = firstName;
this.lastName = lastName;
this.hireDate = hireDate;
}
// Accessors for the fields. JDO doesn't use these, but your application does.
public Long getId() {
return id;
}
public String getFirstName() {
return firstName;
}
// ... other accessors...
}