I just discovered this is valid Kotlin

And Java too!


val x = 1 - - - - - - - - - - - 2 val y = 3 + + + + + + + + + + + 4 val z = 5 + - + - + - + - + - + 6

I actually figured this out while working on my own lexer – it’s basically so that numeric literals with a leading + or – can be disambiguated from arithmetic operations, which requires information more easily acquired later during parsing. Otherwise, this would be difficult to lex correctly:


val w = 3+4

Also fun to note:


val x = 1-----------2 // Lexer detects decrement ops, fails val y = 3+++++++++++4 // Lexer detects increment ops, fails val z = 5+-+-+-+-+-+6 // This works!

So now you can confuse coworkers and increase job security with more obscure and difficult parses. Enjoy!

EDIT: I just discovered this as well:


val x = 3 - +(2 + 4) // Totally valid

Kotlin I believe makes ‘unaryPlus’ an explicit operation, but Java was a surprise to me. Even putting non-constant expressions in the above will work just fine.

submitted by /u/frizzil
[link] [comments]

Continue Reading I just discovered this is valid Kotlin

Arkanoid

Well I have to do a arkanoid game, and I dont know how to do the bricks list… Bricks that a ball that is moving needs to destroy. I need to create a list of bricks so when the ball collides with bricks the bricks are “destroyed” Thanks for the help

submitted by /u/gddo2020
[link] [comments]

Continue Reading Arkanoid

Should I use type inference?

Very simple question here.

Should I do this?


val re1 = txtRe1.text.toString().toIntOrNull() ?: 0

Or this?


val re1: Int = txtRe1.text.toString().toIntOrNull() ?: 0

Or for example:


val spinner: Spinner = findViewById(R.id.spinner)

or


val spinner = findViewById(R.id.spinner)

Thanks.

submitted by /u/HelloWorldzik
[link] [comments]

Continue Reading Should I use type inference?

A little help abut Desktop apps?

Hey guys,

so I’m pretty new to Kotlin, though I know the basics and fundamentals pretty well, and I was interested in building Desktop applications. Currently I’m building my project with TornadoFx, but I have no actual clue about how to compile it to a .exe or .dmg, for example. I was looking around the web and I found all these articles about Kotlin/Native, Compose and KMM, and now I’m a bit confused over all of them.

So can someone explain to me a bit about what are those environments? Can I actually build something compatible with Windows or Mac with Kotlin? Can I stick with TornadoFx and Kotlin (both of which I’m finding myself really comfortable with)? I’d like to have just to have a bit of guidelines about what I should look to learn and to invest some time on.

Thank you so much in advance to everyone!

submitted by /u/NicolaM1994
[link] [comments]

Continue Reading A little help abut Desktop apps?

End of content

No more pages to load