#Specify generics?
15 messages · Page 1 of 1 (latest)
⌛ This post has been reserved for your question.
Hey @hybrid badge! Please use
/closeor theClose Postbutton above when you're finished. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.
TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.
what exactly do you want to do?
Can you give a more concrete example?
you cannot check generics at runtime
I have a method that takes the type of my list, and uses == to compare it to some elements. I’d like to be able to use .matches() instead if the generic happens to be a string
you cannot check the generic type at runtime
but you can check the element
and in general, maybe consider using equals() instead of ==
So like check if input.getClass() is Class<String>?
String.class, but yes
Or check if (input instanceof String s)
Then you can operate on s
Cool, I’ll try that