Skip to content
Advertisement

Tag: generics

Making method generic and attributes

I am using quite a similar method for 4, 5 screens basically to do same thing on List of different objects. Now I extracted that method to reuse it and make it generic. Now while making a list generic I face the issue with attributes. It’s attributes are no longer accessible when made generic. How to overcome this issue. Please

How to implement a generic interface that extends another generic interface in Java?

I am new to Java and working on implementing generic interfaces and that’s where I’d love some help. I want to implement a generic interface in Java that extends another interface. This is how the current interface structure looks like – I want to implement the ItemsProviderInterface interface and provide a definition for convertInput(), convertResponse(), request() methods. Maybe something like

Why java lets me add a Box(Raw type) to a List<Box>

This code works, and I dont understand how the list is able to add a raw type box, I thought type erasure will set the type to their indicated bounds. note: Paper class doesn’t extends Bakery class. EDIT: Is my understanding correct? the compiler typecasts the raw box type so that it can be added to the list? does this

Why can’t I add a type parameter to an overriding method?

I need to implement a method from a class Foo, in my subclass Bar: As you can see, my method would benefit from a type parameter: (I could also use raw types because I know it’ll work, but everything I’ve read says you really shouldn’t do that) Unfortunately, this is illegal – my method foo in Bar “clashes with foo()

Is there a way to see what my code looks like after type erasure?

I would like to know what tool can be used to view code after type erasure. For example, I’d like to see what the following code looks like after type erasure. I know that generic type information is stripped prior to final compilation, replacing type references with Object or boundary types, creating bridge methods, etc. I want to see the

How is compiler inferring type on a generic method?

I have a Storage class: There are two classes where class Child extends Parent: Parent Child Driver class: Because Storage is a generic class, the operations on its method makes sense; I get how case 1 is working. In case 2, with above signature of max in GenericTest, I get the compilation error: The method max(List<T>) in the type GenericTest

Nested generic types in static method

I was trying to develop a generic method that could convert a JSON to a generic object that would have another instantiable generic object inside so I could use it as a parser in several places in my application. I had thought of the following solution, but it doesn’t work: Is there any way to be able to perform such

Advertisement