Hello! I read about generic, Optional class is given as an example.
package chapt03; public class Optional <T> { private T value; public Optional() { } public Optional(T value) { this.value = value; } public T getValue() { return value; } public void setValue(T val) { value = val; } public String toString() { if (value == null) return null; return value.getClass().getName() + " " + value; } } Further in the main method there is such a code fragment:
//параметризация по умолчанию - Object Optional ob3 = new Optional(); System.out.println(ob3.getValue()); Then there is a moment that I just can’t understand and ask for help in understanding it. Quote:
"Declaring a generic-type in the form of
<T>, despite the possibility to use any type as a parameter, limits the scope of the class being developed. Variables of this type can only call methods of theObjectclass. Access to other methods restricts the compiler, preventing possible errors" .
But in main ob3 calls the class method Optional , which is not an Object method. What I do not understand?