package com. liaoxiang. java1;
@MyAnnotation ( value= "rose" )
public class Person extends Creature < String> implements Comparable , MyInterface{
public String name;
private Integer age;
int id;
public Person ( ) {
System. out. println ( "调用了Person的空参构造器" ) ;
}
public Person ( String name) {
this . name = name;
}
private Person ( String name, int age) {
this . name = name;
this . age = age;
}
@Override
public String toString ( ) {
return "Person{" +
"name='" + name + '\'' +
", age=" + age +
", id=" + id +
'}' ;
}
@Override
public int compareTo ( Object o) {
return 0 ;
}
@MyAnnotation ( value = "jack" )
public void show ( ) {
System. out. println ( "我是一个人!" ) ;
}
private Integer display ( String nation, Integer i) throws Exception{
System. out. println ( "我的国籍是:" + nation) ;
return i;
}
public static void info ( ) {
System. out. println ( "静态方法:我是一个中国人" ) ;
}
class Bird { }
}
public class TestOthers {
@Test
public void test1 ( ) {
Class< Person> personClass = Person. class ;
Class< ? super Person> superclass = personClass. getSuperclass ( ) ;
System. out. println ( superclass) ;
}
@Test
public void test2 ( ) {
Class< Person> personClass = Person. class ;
Type genericSuperclass = personClass. getGenericSuperclass ( ) ;
System. out. println ( genericSuperclass) ;
}
@Test
public void test3 ( ) {
Class< Person> personClass = Person. class ;
Type genericSuperclass = personClass. getGenericSuperclass ( ) ;
ParameterizedType parameterizedType = ( ParameterizedType) genericSuperclass;
Type[ ] typeArguments = parameterizedType. getActualTypeArguments ( ) ;
for ( Type typeArgument : typeArguments) {
System. out. println ( typeArgument) ;
}
System. out. println ( ( typeArguments[ 0 ] ) . getTypeName ( ) ) ;
}
@Test
public void test4 ( ) {
Class< Person> personClass = Person. class ;
Class< ? > [ ] interfaces = personClass. getInterfaces ( ) ;
for ( Class< ? > anInterface : interfaces) {
System. out. println ( anInterface) ;
}
}
@Test
public void test5 ( ) {
Class< Person> personClass = Person. class ;
Package aPackage = personClass. getPackage ( ) ;
System. out. println ( aPackage) ;
}
@Test
public void test6 ( ) {
Class< Person> personClass = Person. class ;
Annotation[ ] annotations = personClass. getAnnotations ( ) ;
for ( Annotation annotation : annotations) {
System. out. println ( annotation) ;
}
}
}