代码
Creature类
package com.day0324_1;
import java.io.Serializable;
public class Creature<T> implements Serializable {
private char gender;
public double weight;
private void breath(){
System.out.println("生物呼吸");
}
public void eat(){
System.out.println("生物吃东西");
}
}
myAnnotation注解
package com.day0324_1;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import static java.lang.annotation.ElementType.*;
@Target({TYPE, FIELD, METHOD, PARAMETER, CONSTRUCTOR, LOCAL_VARIABLE})
@Retention(RetentionPolicy.RUNTIME)
public @interface myAnnotation {
String value() default "hello";
}
MyInterface接口
package com.day0324_1;
public interface MyInterface {
void info();
}
Person类
package com.day0324_1;
@myAnnotation(value = "hi")
public class Person extends Creature<String> implements Comparable<String>,MyInterface {
private String name;
int age;
public int id;
public Person(){
}
@myAnnotation(value = "abc")
private Person(String name){
this.name=name;
}
Person(String name,int age){
this.name=name;
this.age=age;
}
@myAnnotation
private String show(String nation){
System.out.println("我的国籍是:"+nation);
return nation;
}
public String display(String interest,int age)throws NullPointerException,ClassCastException{
return interest+age;
}
@Override
public void info() {
System.out.println("我是一个人");
}
@Override
public int compareTo(String o) {
return 0;
}
private static void showDesc(){
System.out.println("我是一个可爱的人");
}
@Override
public String toString() {
return "Person{" +
"name='" + name + '\'' +
", age=" + age +
", id=" + id +
'}';
}
}