public static final int Relationship_User = 0;// 陌生人
public static final int Relationship_Friend = 1;// 通訊錄好友
public static final int Relationship_Requesting = 2;// 已發(fā)送好友請求
@IntDef({Relationship_User, Relationship_Friend,Relationship_Requesting})
@Retention(RetentionPolicy.SOURCE)
public @interface Relationship {
}
使用
@Relationship
private int relationship;
@Relationship
public int getRelationship() {
return relationship;
}
public void setRelationship(@Relationship int relationship) {
this.relationship = relationship;
}
void xxx(){
this.setRelationship(1);// 有警告
if (this.getRelationship() == 1){}// 有警告
this.setRelationship(Relationship_User);// 沒有
if (this.getRelationship() == Relationship_User);// 沒有
}
完整的代碼如下
public class KapModelMessage extends KapModelBase {
public static final int Relationship_User = 0;// 陌生人
public static final int Relationship_Friend = 1;// 通訊錄好友
public static final int Relationship_Requesting = 2;// 已發(fā)送好友請求
@IntDef({Relationship_User, Relationship_Friend,Relationship_Requesting})
@Retention(RetentionPolicy.SOURCE)
public @interface Relationship {
}
@Relationship
private int relationship;
@Relationship
public int getRelationship() {
return relationship;
}
public void setRelationship(@Relationship int relationship) {
this.relationship = relationship;
}
void xxx(){
this.setRelationship(1);// 有警告
if (this.getRelationship() == 1){}// 有警告
this.setRelationship(Relationship_User);// 沒有
if (this.getRelationship() == Relationship_User);// 沒有
}
}