Note that there are some explanatory texts on larger screens.

plurals
  1. POField.getGenericType() returns instance of java.lang.Class instead of Type
    primarykey
    data
    text
    <p>I'm having issues with proguard and some reflection stuff.</p> <p><strong>Myclass.java</strong></p> <pre><code>package not.obfuscated class MyClass { public List&lt;InnerClass&gt; childs; } </code></pre> <p><strong>InnerClass.java</strong></p> <pre><code>package not.obfuscated class InnerClass { //.somestuff } </code></pre> <p>Inside proguard.cfg I have:</p> <pre><code>-keep class not.obfuscated.** {*;} </code></pre> <p>Inside another class I manage to get the "Field" instance for the MyClass.childs field and then try to get the getGenericType to determine which class is inside the List brackets (&lt; InnerClass >)</p> <p>For logging purposes I did the following Log.d code (<em>field</em> is the instance of Field representing MyClass.childs):</p> <pre><code>Log.d("FIELD", field.getName()+" generic type: "+ field.getGenericType()+ " class: "+ field.getGenericType().getClass().getName()); </code></pre> <p>The output is following (2nd line):</p> <p><img src="https://i.stack.imgur.com/MsQuV.png" alt="LogCat output"></p> <p>As you see the field.getGenericType.toString() may be correct, but when I ask for the class it returns java.lang.Class. Indeed, a couple of line afterwards, when I do:</p> <pre><code>ParameterizedType listType = (ParameterizedType) field.getGenericType(); </code></pre> <p>I receive a ClassCastException:</p> <pre><code>java.lang.ClassCastException: java.lang.Class cannot be cast to java.lang.reflect.ParameterizedType </code></pre> <p>I strongly believe this is due to proguard, but as far as I know of proguard I already excluded all the classes inside the not.obfuscated package. As last try I also inserted the line -keep class java.lang.List (obviously nothing happened).</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload