Good morning, everybody, I got warning like this. ...
# android
s
Good morning, everybody, I got warning like this. Why android studio show this warning on these codes? and how to resolve this problem ? Thanks.
t
Press alt+enter and it will suggest an annotation on the line, method, class or file that will ignore the warning. The warning shows up because <*> is not equivalent to <String>
s
But I hate to add more annotation, its really messy . Anything else suggestion to remove this warning?
t
One annotation on the file level will ignore every warning of this type, it isn't that messy
The warning itself is just a warning, you can ignore it
s
Thanks @Tsvetozar Bonev
K 1
l
Well, ignoring the cast might not be the best solution
Also, your check:
is ArrayList<*>
does not assure you you have an
ArrayList<String>
I’d update the check 🙂
s
Yes, I have a lot of models which different types, so I must use
Any
for flexible to cast Type of data in RecyclerView.
l
I’d then add a check before casting it to
ArrayList<String>
s
Screen Shot 2019-09-16 at 3.04.30 PM.png
You mean this things???
l
Yes, I forgot that you cannot do that 😞 Sorry
😢 1
You could introduce nullability for safety 🙂
as? ArrayList<String>?
that would return
null
if the cast fails
s
thanks @Luca Nicoletti, its still warning and suggest to
Array<*>
with
as?
l
I was talking about the second cast
Inside the
if
🙂
👍 1
s
Yes, I have a lot of models which different types, so I must use
Any
for flexible to cast Type of data in RecyclerView.
there are other ways of representing your data where you don’t have to deal with a list of
Any
using something like https://github.com/lisawray/groupie can do a lot of the heavy lifting there for you too