#JAVA CORE

56 messages · Page 1 of 1 (latest)

oak isle
#

I am try'n to make method which contains in superclass this method should produce set of classes that call this method.
I hope the idea will become more clear from this fragment of code
Will try to clear everything by answering your questions, and yea, btw I don't shure that I need to use generics here

tawny grottoBOT
#

This post has been reserved for your question.

Hey @oak isle! 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.

oak isle
#

JAVA CORE

golden lintel
#

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

tawny grottoBOT
golden lintel
#

what problem is this method trying to solve?

golden lintel
#

@oak isle

slate fulcrum
#

wait wtf

#

#1 rule of asking for help in coding

#

SEND THE CODE

#

not a screenshot of the code

#

#❗︱how-to-get-help

golden lintel
#

that's the problem in the method

slate fulcrum
#

can you send the actual code

golden lintel
#

what's the method itself for

slate fulcrum
#

oh wait

#

this isn't ur thread

#

tf

golden lintel
#

lmao

#

that was confusing

slate fulcrum
#

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

golden lintel
#

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?

proven bane
slate fulcrum
#

wait wtf

#

I have never ever seen a static class

#

...

golden lintel
slate fulcrum
#

well a nested static class

golden lintel
#

inner classes are much less common than nested classes

slate fulcrum
#

why would you use it tho

#

idk it just seems like a confusing way to write code

golden lintel
#

Stream's Builder is a nested class

slate fulcrum
#

ah

slate fulcrum
#

just like

#

when would u use it

#

cuz i genuinely don't know

golden lintel
#

ah

#

mb

slate fulcrum
#

altho actually if u have the time to explain it can u put it in general

#

#general

golden lintel
#

(this might be a topic of its own, if you want to continue on this stuff make a help thread pls)

split dragon
#

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);

tawny grottoBOT
#

💤 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.