ClassCastException about anonymous class (java)

now i get some logs as below (log-1)

java.lang.ClassCastException: android.widget.LinearLayout$LayoutParams cannot be cast to ClassA$1
at android.widget.LinearLayout.measureHorizontal(LinearLayout.java:1010)
...


line 1010

final LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) obj.method();//line 1010


I think the log should be like this (log-2)

java.lang.ClassCastException: ClassA$1 cannot be cast to android.widget.LinearLayout$LayoutParams

I wannna know why I can get log-1, right?
If log-1 is correct, then how can I write code to create such an exception?

ps: I know that ClassA $ 1 is an anonymous class.
ps: I get this magazine in the monkey test and it is hard for him to reappear

someone will tell me:

MyInterface my = ClassA$1;//$1 is an anonymous class which implements MyInterface
my.getClass().cast(lp);

then the log will look like log-1
but why didn’t the log indicate the casting line?
and I check the framework framework / base / core, nobody calls the method "? java.lang.Class.cast (Object obj)"
any ideas?

+5
1

. , , , .

, ?

  • , .
  • .
  • ... - , . ( , , stacktrace , - .)
  • , stacktrace ... .

:

  • , .
  • SSCE , .
+2

All Articles