本文整理匯總了Java中java.lang.reflect.Field.toString方法的典型用法代碼示例。如果您正苦於以下問題:Java Field.toString方法的具體用法?Java Field.toString怎麽用?Java Field.toString使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.lang.reflect.Field
的用法示例。
在下文中一共展示了Field.toString方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getFieldLocation
import java.lang.reflect.Field; //導入方法依賴的package包/類
public Location getFieldLocation(final Field field) {
return new Location() {
@Override
public String toString() {
return field.toString();
}
};
}
示例2: assertStaticClassVarsAreFromPackage
import java.lang.reflect.Field; //導入方法依賴的package包/類
private static boolean assertStaticClassVarsAreFromPackage() {
//String packagename = System.getProperty("jawk.rtPackgeName", "org.jawk.jrt");
String packagename = "org.jawk.jrt";
if (packagename != null) {
// use reflection to get all static Class definitions
// and verify that they are members of the
// runtime package
Class c = AwkCompilerImpl.class;
// foreach field in declared in the class...
for (Field f : c.getDeclaredFields()) {
int mod = f.getModifiers();
// if a "private static final" member...
if ( (mod & Modifier.PRIVATE) > 0
&& (mod & Modifier.STATIC) > 0
&& (mod & Modifier.FINAL) > 0
&& f.getType() == Class.class)
{
try {
// obtain the value of the field
// and apply it here!
Object o = f.get(null);
Class cls = (Class) o;
if (!cls.getPackage().getName().equals(packagename)) {
throw new AssertionError("class " + c.toString() + " is not contained within '" + packagename + "' package. Field = " + f.toString());
}
} catch (IllegalAccessException iae) {
throw new AssertionError(iae); // NOTE Thought there is an AssertionError#AssertionError(String, Throwable) ctor aswell, it was only introduced in Java 1.7, so we should not yet use it.
}
}
}
}
// all's well
return true;
}