Skip to content

Tag: generics

Unable to override generic method in java

I am getting errors like Main.java:12: error: TextMessage is not abstract and does not override abstract method setContent(T) in Message class TextMessage extends Message { ^ where T is a type-variable: T extends Object declared in method setContent(T) 1 error Answer Your method declaration: hides the type pa…

How to declare a generic method in Java?

I am learning Java generics and am confused by the method signature. It seems as if people are using it differently in every example I come across. For example, on the site Baeldung, this is the example they give: And then they go on to say this: The <T> in the method signature implies that the method w…

why is this still need to cast in java?

error right DefaultLiteProcessScope extends DefaultLiteProcessScope,but it is till need to be cast?why? Answer What you are doing here is wrong. You want to return some subtype of DefaultLiteProcessScope from the build method. However, you hard code the return type like this: new DefaultLiteProcessScope(). No…