當前位置: 首頁>>代碼示例>>Java>>正文


Java Field.toString方法代碼示例

本文整理匯總了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();
        }
    };
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:10,代碼來源:ReflectionNavigator.java

示例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;
}
 
開發者ID:virjar,項目名稱:vscrawler,代碼行數:35,代碼來源:AwkCompilerImpl.java


注:本文中的java.lang.reflect.Field.toString方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。