Java Tutorial/Apache Common/ClassUtils

Материал из Java эксперт
Перейти к: навигация, поиск

ClassUtils.GetAllInterfaces

import org.apache.rumons.lang.ClassUtils;
public class MainClass {
  public static void main(String[] args) {
    System.out.println("1) Interfaces implemented by java.lang.String >>> "
        + ClassUtils.getAllInterfaces(String.class));
  }
}



1) Interfaces implemented by java.lang.String >>> [interface java.io.Serializable, interface java.lang.ruparable, interface java.lang.CharSequence]



ClassUtils.Get All Superclasses

import org.apache.rumons.lang.ClassUtils;
public class MainClass {
  public static void main(String[] args) {
    System.out.println("2) SuperClasses of java.lang.String >>> " +
        ClassUtils.getAllSuperclasses(String.class));
  }
}



2) SuperClasses of java.lang.String >>> [class java.lang.Object]



ClassUtils.GetPackageName

import org.apache.rumons.lang.ClassUtils;
public class MainClass {
  public static void main(String[] args) {
    System.out.println("3) PackageName of a string >>> " +
        ClassUtils.getPackageName("A String", "IfNull"));
  }
}



3) PackageName of a string >>> java.lang



ClassUtils IsAssignable

import org.apache.rumons.lang.ClassUtils;
public class MainClass {
  public static void main(String[] args) {
    System.out.println("4) Every String is an Object = " +
        ClassUtils.isAssignable(String.class, Object.class));
  }
}



4) Every String is an Object = true



ClassUtils IsAssignable2

import org.apache.rumons.lang.ClassUtils;
public class MainClass {
  public static void main(String[] args) {
    System.out.println("5) Every Object is an String = " +
        ClassUtils.isAssignable(Object.class, String.class));
  }
}



5) Every Object is an String = false