Posts

Showing posts with the label java 5 features

Java 5: Covariant Return Type

Before Java 1.5, when we override a Parent class method then we need to have same return type of method in child class.  From Java 5 onwards, we can override a method by changing its return type, but overriding method's return type should be a sub-type of overridden method return type. For example, class Parent {    public Parent getObject() {      return this;    } } class Child extends Parent {    public Child getObject() {      return this;   }    public void print() {      System.out.println("Child class method..!");   }   public static void main(String[] args){     new Child().getObject().print();   } }

Java 5 (Tiger) Features

Following are some of the Java 1.5 release: Static import @override annotatio n Covariant return types For each loop Auto Boxing/UnBoxing Varargs Scanner class Generics Type safe Enums java.lang.concurrent package Annotations (Metadata)