get Field Path from package, class to field name - Android java.lang.reflect

Android examples for java.lang.reflect:Field Name

Description

get Field Path from package, class to field name

Demo Code

/**//  w  w  w .j a  va2s.c  o m
 * utility functions to extract and set fields in objects using java reflection
 * @author Matthew
 * Copyright (c) 2013 Visible Automation LLC.  All Rights Reserved.
 *
 */
//package com.java2s;
import java.lang.reflect.Field;

import java.util.Stack;

public class Main {
    public static String getFieldPath(Stack<Class> breadcrumb, Field field) {
        StringBuffer sb = new StringBuffer();
        for (int i = breadcrumb.size() - 1; i >= 0; i--) {
            Class c = breadcrumb.get(i);
            sb.append(c.getCanonicalName());
            sb.append('.');
        }
        sb.append(field.getName());
        return sb.toString();
    }
}

Related Tutorials