https://kotlinlang.org logo
#announcements
Title
# announcements
g

gabrielfv

07/26/2017, 10:33 PM
It is possible to make it like
Copy code
val something = someExpr()
    get() = someOtherExpr()
Copy code
class Foo {
    var bar = 2
    	get() {
            tar *= 4
            return tar
        }
    
    var tar = 3
}
😱 3
d

diesieben07

07/26/2017, 10:49 PM
Please don't ever do this... 😄
🧌 5
c

cedric

07/28/2017, 12:22 PM
I've always been bothered by the fact that functions can be declared with
=
, I just don't understand the point in having two ways to declare functions
g

gabrielfv

07/28/2017, 8:05 PM
Important to point that out, @diesieben07 😂
@cedric I like it better for those oneliners that you would sometimes find out there
Copy code
int sum(int a, int b) { return a + b; }
That's not something I'd like to see, particularly, and now there's no excuse if such thing appears when you could just
Copy code
fun sum(a: Int, b: Int) = a + b
Syntatic sugar to less orthodox programmers
c

cedric

07/28/2017, 8:13 PM
But
int sum(int a, int b) { return a + b; }
has the merit of being consistent and not offering two ways to do the same thing
int sum() = ...
is inconsistent (and on a personal level, it's weird to see
() =
)
g

gabrielfv

07/29/2017, 5:58 PM
Well, I do agree it is weird, specially for `get`s since these don't ever take arguments.
But none beats that:
val sum = { a: Int, b: Int -> a + b }
c

cedric

07/29/2017, 6:02 PM
Indeed but it doesn't generalize to functions with parameters
☝️ 1
4 Views