Anonymous types in java like in c#

I was studying about anonymous types in c# and wondering if something similar exists in java. Does Java have something like anonymous types in c#?

Jon Skeet
people
quotationmark

Well there are types in Java which are anonymous in that you can't refer to them by name, but they have very little in common with anonymous types in C#. In Java they're anonymous inner classes, e.g.

Runnable x = new Runnable() {
    private int x = 10;

    @Override public void run() {
        System.out.println(x);
        x++;
    }
};
x.run(); // Prints 10
x.run(); // Prints 11

There's no equivalent to C#'s notion of "create a type which has a bunch of read-only properties whose types are inferred from the initialization expression, complete with equality and handy string conversion implementations automatically provided". Anonymous inner classes in Java are usually used to implement interfaces and extend abstract classes easily - where you'd usually use a lambda expression in C#.

people

See more on this question at Stackoverflow