Here’s my sample code: I think I should be able to add integer to items, but compilation fails: Anyone knows what’s wrong here? Answer Let us consider a more complete version of your example: Suppose for the sake of argument that the compiler says that is OK. And now we will create an instance and call the func method: Here
Tag: bounded-types
Not able to create generic bounded class objects with interface
I am trying to use bounded types with generics to create generic objects of subclasses (these implement an interface). But I am getting type mismatch errors when initializing objects with the subclasses. Here is the interface: Here’s the class that implements this interface: Now I created 2 classes (SegmentPageScanResult and ItemProcessor) with the bounded generic type as: and When I
Using an Interface as a super type for Enum classes – problem with accessing Enum-specific methods
I’ve been attempting to implement an interface in my enums in order to have rules for a simulation I’m making. I am trying to access enum-methods such as values() and ordinal() (on objects). However, even with upper-bounding my classes with my interface name, I still cannot access these methods without overriding them in my interface, which won’t work. I’m trying