There is an object
ArrayList<String> list = new ArrayList<>(); I want to get the type of this object in this form
java.util.ArrayList<java.lang.String> But using the method .getClass I get the type in this form:
java.util.ArrayList How can I get the type of object in the right format for me
This is the code I did not work.
private void invoke(String arg1, String arg2, Object dataObject) { Method[] methods = MyClass.class.getDeclaredMethods(); for (Method m : methods) { if (m.getName().equals("invoke")) { Type[] methodTypes = m.getGenericParameterTypes(); for (int i = 0; i < methodTypes.length; i++) { Log.wtf(TAG, "Check class: " + methodTypes[i]); if (methodTypes[i] instanceof ParameterizedType) { ParameterizedType t = (ParameterizedType) methodTypes[i]; Class<?> cls = (Class<?>) t.getActualTypeArguments()[0]; Log.d(TAG, T.class.getName() + "<" + cls.getName() + ">"); } } } } } The logs will be this:
java.lang.String java.lang.String java.lang.Object
listempty? - post_zeew