About creating instances of non-static inner classes with Java-Like syntax

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

About creating instances of non-static inner classes with Java-Like syntax

Daniel.Sun
Hi all,

       When I tried to carry out the step1 of Phoenix plan( i.e. make Parrot
support Java syntax as a dialect), I found Groovy does not support  some
code like `outer.new Inner()` to create instances of non-static inner
classes[1]. So I set aside some time to support the syntax in the Parrot
parser[2].  I wish you would like it.

P.S. "Differences with Java"[1] is a bit outdated for Groovy 3 ;-)

Cheers,
Daniel.Sun
[1] http://groovy-lang.org/differences.html
[2]
https://github.com/danielsun1106/groovy-parser/tree/new-non-static-inner-class




--
Sent from: http://groovy.329449.n5.nabble.com/Groovy-Dev-f372993.html
Reply | Threaded
Open this post in threaded view
|

Re: About creating instances of non-static inner classes with Java-Like syntax

Daniel.Sun
Reply | Threaded
Open this post in threaded view
|

RE: About creating instances of non-static inner classes with Java-Like syntax

eric.milles
I know it is part of the Java spec, but do you know anyone that actuallky does that?  I'm just curious as I've never once seen a need for it.

Array creation is the one item that comes up most often for me when converting a source file from Java to Groovy.

Reply | Threaded
Open this post in threaded view
|

Re: About creating instances of non-static inner classes with Java-Like syntax

Remko Popma
Eric,

Yes this is used.

For example, picocli has an Ansi enum (ON, OFF, AUTO), with a nested inner class Text.

A Text instance is created with
`currentAnsi.new Text(“@|bold hello|@“);`
The outer class determines whether Ansi escape codes are emitted when the text is rendered.

I’m sure it’s possible to design things differently but if you are asking “is this actually used“, the answer is yes.

(Shameless plug) Every java main() method deserves http://picocli.info

> On Apr 12, 2018, at 2:36, <[hidden email]> <[hidden email]> wrote:
>
> I know it is part of the Java spec, but do you know anyone that actuallky does that?  I'm just curious as I've never once seen a need for it.
>
> Array creation is the one item that comes up most often for me when converting a source file from Java to Groovy.
>
Reply | Threaded
Open this post in threaded view
|

Re: About creating instances of non-static inner classes with Java-Like syntax

paulk_asert
In reply to this post by eric.milles
One of the more common forms of array creation is catered for in the Parrot parser.


On Thu, Apr 12, 2018 at 3:36 AM, <[hidden email]> wrote:
I know it is part of the Java spec, but do you know anyone that actuallky does that?  I'm just curious as I've never once seen a need for it.

Array creation is the one item that comes up most often for me when converting a source file from Java to Groovy.


Reply | Threaded
Open this post in threaded view
|

Re: About creating instances of non-static inner classes with Java-Like syntax

Jesper Steen Møller
In reply to this post by Remko Popma
Hi Remko,

I'm so glad that somebody's used it (in Java). I've fixed an issue or two over in Eclipse JDT around this very construct (placement new) - I had to read the spec to find out how it was supposed to work...

-Jesper

> On 11 Apr 2018, at 16.01, Remko Popma <[hidden email]> wrote:
>
> Eric,
>
> Yes this is used.
>
> For example, picocli has an Ansi enum (ON, OFF, AUTO), with a nested inner class Text.
>
> A Text instance is created with
> `currentAnsi.new Text(“@|bold hello|@“);`
> The outer class determines whether Ansi escape codes are emitted when the text is rendered.
>
> I’m sure it’s possible to design things differently but if you are asking “is this actually used“, the answer is yes.
>
> (Shameless plug) Every java main() method deserves http://picocli.info
>
>> On Apr 12, 2018, at 2:36, <[hidden email]> <[hidden email]> wrote:
>>
>> I know it is part of the Java spec, but do you know anyone that actuallky does that?  I'm just curious as I've never once seen a need for it.
>>
>> Array creation is the one item that comes up most often for me when converting a source file from Java to Groovy.
>>