Menu
Is there any way I can have a ClassB that overrides it with a concrete class, similar to the previous example? I've come up with something that works, which is to parameterize both the class and the method, but I'm wondering if there's another way. Now, ignoring the previous ClassA and ClassB, if I have an abstract ClassA, which has a generic method: public void doSomething(T data) If I have ClassA, I can override it with a subclass that references a concrete class, such as ClassB extends ClassA, then anywhere ClassA uses T, ClassB can use a String. I'm experimenting with generics in Java, and thought of this example.
0 Comments
Leave a Reply. |