Generic List setter ?

It's possible to have a method that not matter what kind of list you send, it would set it to the corresponding variable ? ex.
List<Foo> foo = new ArrayList();
List<Bar> bar = new ArrayList();

public <T> void setList(List<T> myList){
if(myList instanceof List<Foo>) this.foo = myList;
if(myList instanceof List<Bar>) this.bar = myList;
}
List<Foo> foo = new ArrayList();
List<Bar> bar = new ArrayList();

public <T> void setList(List<T> myList){
if(myList instanceof List<Foo>) this.foo = myList;
if(myList instanceof List<Bar>) this.bar = myList;
}
6 Replies
JavaBot
JavaBot2y ago
This post has been reserved for your question.
Hey @keplerk! 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.
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
keplerk
keplerkOP2y ago
That's what i feared :Sad: oh well, it worth the try, thanks
JavaBot
JavaBot2y ago
If you are finished with your post, please close it. If you are not, please ignore this message. Note that you will not be able to send further messages here after this post have been closed but you will be able to create new posts.
keplerk
keplerkOP2y ago
JavaBot
JavaBot2y ago
Post Closed
This post has been closed by <@306591040406683649>.
Want results from more Discord servers?
Add your server