#Check for a specific generic type

14 messages · Page 1 of 1 (latest)

junior pivot
#

I have a variable of the type Supplier<? extends Item> and want to check if it’s Supplier<? extends BlockItem>. Is there a way to do that? instanceOf doesn’t seem to work according to IntelliJ. Minecraft forge 1.16.5 so java 8.

tawdry onyxBOT
#

This post has been reserved for your question.

Hey @junior pivot! Please use /close or the Close Post button above when your problem is solved. 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.

junior pivot
#

For context as to what I’m doing I have a function to register a block item from a block but it needs to be delayed from the last function that has the actual block, but I’m trying to make a HashMap keying the blocks to their item in case I need that at some point

#

So I’d like to be able to retrieve the block from the BlockItem

#

But the same function is used for non block items

shrewd citrus
#

can't you use Block#byItem ?

junior pivot
#

Probably, I was just giving context on how I came up with my question.

#

My question is basically is there a way to check the type of a generic if I have a variable of type X<? extends T>

#

Basically can I check if that variable is an instance of X<? extends Y> where Y extends T

next axle
#

I'm sure you understand that in the case of List it is impossible by definition

#

So it may possible with your particular generic type, but in general it's not

junior pivot
#

Ok thank you

tawdry onyxBOT
# junior pivot Ok thank you

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.