I have seen a method like shown below:
protected <T extends ABC> T save( T Acd, boolean en) {
What does it do? What is these type of method declarations called in Java?
Implementing the Extends Comparable<T> Interface in Java This method compares the object with the specified object for the order. It returns a negative integer if the object is less than specified. It will return zero if the object and the specified object are equal.
super is a lower bound, and extends is an upper bound.
super T denotes an unknown type that is a supertype of T (or T itself; remember that the supertype relation is reflexive). It is the dual of the bounded wildcards we've been using, where we use ? extends T to denote an unknown type that is a subtype of T .
A bound is a constraint on the type of a type parameter. Bounds use the extends keyword and some new syntax to limit the parameter types that may be applied to a generic type. In the case of a generic class, the bounds simply limit the type that may be supplied to instantiate it.
It is called a generic method. This whole concept is called "Generics" in Java. That declaration means T can be any type that is subclass of ABC.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With