Enter your keyword

Advanced Java – GENERICS

In Java, Generic classes and generic methods are used by programmers to point out, with use of a single declaration of method, a set of methods that are related. It is also used to specify a single class declaration with a set of related types. Another advantage of generics is that it provides safety during compile time which will allow programmers to get invalid types during compile time. With use of Java’s generic concept, one can write a generic method for sorting out arrays of objects, after which the generic method can be invoked with integer arrays, string arrays, double arrays etc. in order to sort the array elements.

A programmer can write a single generic method declaration which can be called with different types of arguments. Depending on the kinds of arguments that are passed to the generic method, the compiler can handle every method call accordingly. There are certain rules and syntax for defining Generic methods that are covered in the Java 8 course in depth where students are given assignments to work with them.