It is possible to make it like ```val something = ...
# announcements
g
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
Please don't ever do this... 😄
🧌 5
c
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
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
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
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
Indeed but it doesn't generalize to functions with parameters
☝️ 1