Specify generics?
Can I do something like
class ArrayList<String> extends ArrayList<E> {
? I have a class with a generic and I want to override a method if the type is string, so I can use .matches() instead of ==. Being able to check the type of a generic would also work.8 Replies
⌛
This post has been reserved for your question.
Hey @blockgoblin31! Please useTIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here./close
or theClose Post
button above when you're finished. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.
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>?
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
Cool, I’ll try that
Post Closed
This post has been closed by <@501514065068294154>.