#JAVA CORE
56 messages · Page 1 of 1 (latest)
⌛ This post has been reserved for your question.
Hey @oak isle! 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.
JAVA CORE
yeah i have no idea what you're trying to do here
you can't create new instances of generic types
generics are reduced to Object at runtime due to type erasure
what problem is this method trying to solve?
@oak isle
you can't instantiate a generic type
wait wtf
#1 rule of asking for help in coding
SEND THE CODE
not a screenshot of the code
#❗︱how-to-get-help
yeah no that's not it
that's the problem in the method
can you send the actual code
what's the method itself for
wait
this code just doesn't make sense
why does he have a generic
wtf
he has a list of pets who have a generic? and then he tries adding an instantiation of the generic T to a list that holds pet objects
huh
that's why i asked what i did
@oak isle see this link: https://xyproblem.info
and please answer: what problem is this method trying to solve?
Asking about your attempted solution rather than your actual problem
lol but true it was
it's not a top level class
well a nested static class
inner classes are much less common than nested classes
separation of concerns. it's used a ton
Stream's Builder is a nested class
ah
no i didn't mean "why would you use it" in the rhetoric of "you shouldn't use it"
just like
when would u use it
cuz i genuinely don't know
(this might be a topic of its own, if you want to continue on this stuff make a help thread pls)
you can pass (Suppler<T>) which will create the object. your method cant really know if passed object has which contructor .. remember not all constructors dont need arguments. so its not generic anymore 🙂
calling code will be something similar to
petsContainer.create(Dog::new, amount);
💤 Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived.
If your question was not answered yet, feel free to re-open this post or create a new one.