Diamond Operator in Java

Directly coming to the point,Diamond operator gives the flexibility of not writing the type on the right hand side.
For example:

 List<String> geeks = new ArrayList<String>();
 ******can be written as********
List<String> geeks = new ArrayList<>();

Now this was introduced in JDK 7 but there was a problem in diamond operator for JDK 7 which was
With the help of Diamond operator, we can create an object without mentioning the generic type on the right hand side of the expression. But the problem is it will only work with normal classes. Suppose you want to use the diamond operator for anonymous inner class then compiler will throw error message like below:

abstract class Animals<T> {
    abstract T walk();
}

public class anonymous {
    public static void main(String[] args) {
        Animals<String> animals = new Animals<>() {
            @Override
            String walk() {
                return "tap tap";
            }
        };
        String walk = animals.walk();
        System.out.println("Animals walk like: " + walk);
    }
}
//I am using so I was getting following error:
/*Error:(9, 46) java: cannot infer type arguments for com.ibm.wsc.infohub.processing.rule.metadata.Animals<T>
  reason: cannot use '<>' with anonymous inner classes*/
*********To Solve above issue if we dont have java 1.9 or older 
then we need to define the type on the right hand side as well******************

abstract class Animals<T> {
    abstract T walk();
}

public class anonymous {
    public static void main(String[] args) {
        Animals<String> animals = new Animals<String>() {
            @Override
            String walk() {
                return "tap tap";
            }
        };
        String walk = animals.walk();
        System.out.println("Animals walk like: " + walk);
    }
}
//Output will be : Animals walk like: tap tap

But if we have java JDK 9 or above this issue is resolved , we don’t have to give the type on the right hand side for anonymous inner class as well.

For more info follow the given two links:
https://www.geeksforgeeks.org/diamond-operator-for-anonymous-inner-class-with-examples-in-java/
https://www.baeldung.com/java-diamond-operator