groovy-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Andres Almiray <aalmi...@gmail.com>
Subject Re: [RFE] Methods as expressions
Date Tue, 20 Mar 2018 11:08:12 GMT
FYI you can also write it like

@Controller("/") class HelloController {
    @Get("/hello/{name}")
    String hello(String name) { "Hello $name" }
}

So you're only saving 2 characters (space and closing brace) by following
Kotlin/Scala syntax.

Cheers,
Andres


-------------------------------------------
Java Champion; Groovy Enthusiast
JCP EC Associate Seat
http://andresalmiray.com
http://www.linkedin.com/in/aalmiray
--
What goes up, must come down. Ask any system administrator.
There are 10 types of people in the world: Those who understand binary, and
those who don't.
To understand recursion, we must first understand recursion.

On Tue, Mar 20, 2018 at 11:41 AM, C├ędric Champeau <cedric.champeau@gmail.com
> wrote:

> Hi,
>
> One of the Kotlin features I really like is the short-hand notation for
> simple expression methods:
>
> class Foo {
>     fun truth(): Integer = 42
> }
>
> For example, in Groovy, you write:
>
> @Controller("/") class HelloController {
>
>     @Get("/hello/{name}")
>     String hello(String name) {
>         return "Hello $name"
>     }
> }
>
>
> but we could write:
>
> @Controller("/")
> class HelloController {
>     @Get("/hello/{name}")
>     String hello(String name) = "Hello $name"
> }
>
>
> It's more concise and makes the "functional style" more readable. Is this
> something Groovy users would appreciate?
>
>

Mime
View raw message