Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is inner creator (objectinstance.new) in Java?

Tags:

java

I came across something like

ArgProcessor argProcessor = runWebApp.new ArgProcessor(options);

This line is from the source of GWT. By digging into Java's grammar I found it to be (".new") inner creator.

But I didn't find any proper documentation about why exactly we need the inner creator.

How does this differ from a normal object/instance creator?

like image 969
Deepak Patil Avatar asked May 04 '11 18:05

Deepak Patil


1 Answers

It is for creating an object of the inner class type.

for example: look at this

http://www.javabeat.net/tips/124-inner-classes-in-java.html

ie:

class Outer{

  final int z=10;

  class Inner extends HasStatic {
    static final int x = 3;
    static int y = 4;
  }

  public static void main(String[] args) {
    Outer outer=new Outer();
    System.out.println(outer.new Inner().y);
  }
}
like image 191
GuruKulki Avatar answered Sep 28 '22 17:09

GuruKulki