1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
| @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 interests,int age) throws NullPointerException,ClassCastException{ return interests + 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 + '}'; } }
@Target({TYPE, FIELD, METHOD, PARAMETER, CONSTRUCTOR, LOCAL_VARIABLE}) @Retention(RetentionPolicy.RUNTIME) public @interface MyAnnotation { String value() default "hello"; }
public class Creature<T> implements Serializable { private char gender; public double weight;
private void breath(){ System.out.println("生物呼吸"); }
public void eat(){ System.out.println("生物吃东西"); } }
public interface MyInterface { void info(); }
|