Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have an object in java, I know that this object contains useful informations for me, the problem is I don't know the names of the fields, I don't know if this object contains real data or just references, considering this and the fact that I only know the label of this object, what options do I have to debug this data structure and get informations out of it?

It's possible to list every objects corresponding to a particular type?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
203 views
Welcome To Ask or Share your Answers For Others

1 Answer

To print (and search) a field in a class :

static Object fieldOdClass(final String className,
        final String valeurRecherche1) {
        try {
            final Field[] f = Class.forName(className).getFields();
            for (int i = f.length - 1; i >= 0; i--) {
                System.out.println(f[i].toString());
                if (f[i].toString().endsWith(valeurRecherche1)) {
                    return f[i].toString();
                }
            }
        } catch (final ClassNotFoundException e) {
            // manage errors;
        }
    }

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...