#Something with Unchecked Calls...

1 messages · Page 1 of 1 (latest)

vestal vapor
#

Hey guys!

I've been struggling for way too long to figure this out. The hardest thing is I don't know what the proper terminology if for this situation is so googling didn't help much.

Here's the situation:

I have a class that has the <E> thing in it (what is that type of class called?) It looks like this:
public class Conditional<E> extends MenuItem { ... }

Elsewhere I want to check if a MenuItem is an instance of a Conditional<Player>

However, if I do:
if (menuItem instanceof Conditional<Player>) { ... }
It says ''MenuItem' cannot be safely cast to 'Conditional<Player>'

Simply casting to Conditional works, but I would like to know specifically what's inside the "<>"

This is the first time I'm making classes with <> in them (can't figure out what those are called) so I'm quite confused about all this :P

Any help or guidance is much appreciated!

civic kayak
#

They are called generics

vestal vapor
#

Tysm! At least I now know what to google :)

civic kayak
#

Isnt Class::isAssignableFrom something?

#

Instanceof Conditionele<?> Would t work

hardy pine
#

The issue you experience is called generic signature erasure. It cannot be fixed