2

Having this function

public ParameterMethodParameterBuilder withParameter() {
        MethodParameter parameter = new MethodParameter();

  return withParameter(parameter).new ParameterMethodParameterBuilder(parameter);
}

What is the mean of the experession below

withParameter(parameter).new ParameterMethodParameterBuilder(parameter)
1
  • 1
    post withParameter(MethodParameter parameter) method Commented Apr 22, 2014 at 11:40

4 Answers 4

3

The syntax obj.new Inner() creates and returns an instance of the inner class(*) Inner that is linked to the instance obj of the encapsulating class.

When an inner class is declared, you need an instance of the encapsulating class to instantiate the inner class. The syntax you are confronted to is exactly for this purpose.

Here is the simplest example for this:

public class MainClass {
    public class InnerClass {
    }
}

You would instantiate InnerClass this way:

MainClass mc = new MainClass();
mc.new InnerClass();

(*) inner class = non-static nested class

Sign up to request clarification or add additional context in comments.

1 Comment

could you please help me with that stackoverflow.com/questions/23205527/…
2

ParameterMethodParameterBuilder is an inner class of whatever returning type of withParameter(MethodParameter parameter) method.

You care creating a new object of that inner class ParameterMethodParameterBuilder which having outer reference returned by withParameter(parameter) method

1 Comment

could you please help me with stackoverflow.com/questions/23205527/…
0

It creates a new instance of a nested class:

public class MethodParameter() {

    public class ParameterMethodParameterBuilder(/* ... */) {

        //...

    }

    //...
}

3 Comments

Looking again at the original post, what makes you think the class ParameterMethodParameterBuilder is declared static? I suppose exactly that it isn't.
The inner class is very unlikely to be static.
Small mistake on my part, it definitely wouldn't be static. Just commonly how I declare my nested classes :)
0

withParameter(parameter) method returns MethodParameter instance and you are trying to create

object of ParameterMethodParameterBuilder static inner class,

so syntax goes like this MethodParameter.new ParameterMethodParameterBuilder (parameter) to create your inner static class object

let me know for any issues.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.