I mean
public class Generic<T> extends T{
}
if I have two classes, in my case it is Response and Request, and several classes with own fields, i want extend response or request depending on the situation or vice versa extend classes. But i do not want to create another classes
That's impossible logically per java as by definition of inheritance you always extend a class not a type
. If you trying to do so, you will see following error:
Error:(3, 48) java: unexpected type
required: class
found: type parameter T
So, it clear that,
A class can not inherit from it's type
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.