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
JavaBot
JavaBot2y ago
This post has been reserved for your question.
Hey @blockgoblin31! Please use /close or the Close 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.
TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.
dan1st
dan1st2y ago
what exactly do you want to do? Can you give a more concrete example? you cannot check generics at runtime
blockgoblin31
blockgoblin31OP2y ago
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
dan1st
dan1st2y ago
you cannot check the generic type at runtime but you can check the element and in general, maybe consider using equals() instead of ==
blockgoblin31
blockgoblin31OP2y ago
So like check if input.getClass() is Class<String>?
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
blockgoblin31
blockgoblin31OP2y ago
Cool, I’ll try that
JavaBot
JavaBot2y ago
Post Closed
This post has been closed by <@501514065068294154>.

Did you find this page helpful?