Type inference in Java 5

Generics introduced a type system to enable the developers to abstract over types. It restricted a class, interface, or method to working with instances of specified types, providing compile type safety. Generics were defined to add compile type safety to the Collections framework. Generics enable programs to detect certain bugs during compilation, so they can't creep into the runtime code. 

Java used type inference for generic method type arguments in Java 5. Consider the following code:

List<Integer> myListOfIntegers = Collections.<Integer>emptyList(); // 1

Instead of the preceding code, you could use the following code:

 List<Integer> myListOfIntegers = Collections.emptyList(); // 1 
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.15.12.34