Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Store attribute type #3

Open
mhagnumdw opened this issue Nov 13, 2018 · 1 comment
Open

Store attribute type #3

mhagnumdw opened this issue Nov 13, 2018 · 1 comment

Comments

@mhagnumdw
Copy link
Owner

mhagnumdw commented Nov 13, 2018

Currently, the BeanMetaInfo class stores only the attribute name. In some cases it would be interesting to know the attribute type as well.

@mhagnumdw
Copy link
Owner Author

Perhaps, in order not to overload the API, it is better to store in the generated class the original class type and just that.

It would be up to those who make use of the API to retrieve the attribute type. Being able to do something like this:

public class ReflectionUtils {

    public static Class<?> getType(Object classOrObject, String attributeName) throws NoSuchFieldException, SecurityException {
        final Class<?> clazz;
        if (classOrObject instanceof Class) { // It's a class
            clazz = (Class<?>) classOrObject;
        } else { // It is an object
            clazz = classOrObject.getClass();
        }
        return clazz.getDeclaredField(attributeName).getType();
    }

}

Advantage: does not overload the API and the code above is a simple solution.

Disadvantage: If it is a batch call with thousands or millions of calls, it would be much faster if the type information was already available statically.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant