Code Discussion


I was attending an android development course, in Member classes the instructor said that to change value of variable in class we should type

"fun main() {

var umar = Person("Umar", "Akram", 16)

umar.hobby = "Playing chess"

umar.getHobby()

}

class Person(firstName:String = "John", secondName:String = "Doe"){

var age : Int? = null

var hobby : String = "Watching Netflix"

var firstName :String? = null ".

Then I was wondering about that we can use (

var hobby = "Anything"

) instead
what do you think?

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

Continue Reading Code Discussion

KVision 3.12.0 is released (with support for Micronaut framework)

KVision is an open source web framework created for Kotlin/JS. It allows developers to build modern web applications with the Kotlin language.

I have released KVision 3.12.0, with a new module supporting the Micronaut web framework. Micronaut provides a simple compile-time aspect-oriented programming API that does not use reflection. It’s perfect for building modular, easily testable microservice and serverless applications.

There are some new example applications, including the new fullstack template, which present how to build KVision fullstack apps with Micronaut.

For more details about this release see the changelog.

As always, any feedback is appreciated!

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

Continue Reading KVision 3.12.0 is released (with support for Micronaut framework)

Automatically generating Dokka API docs using Github Actions and deploying to Github Pages

I just got this working and though it would be useful to share.

First step is to configure Dokka in your build.gradle:


plugins { ... id 'org.jetbrains.dokka' version '1.4.0-rc' ... }

Next configure the Github Action, you can see how I’ve done it here.

This will deploy the documentation to the

gh-pages

branch of your respository, see here for more information.

You can see the result here: http://dokka.kweb.io/kweb-core/

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

Continue Reading Automatically generating Dokka API docs using Github Actions and deploying to Github Pages

Referencing nameless objects in a nested JSON

Hey guys.

I tried to look for an answer for this on google but I don’t know what the correct term for my problem is. Also, as you might have guessed I am new to Kotlin.

I am generating a nested JSON with gson with the root being this:
private data class MasterJson(val ships: MutableList<PlayerShipJson>)

That results in a JSON that is structured like this:
[

[

{

“playerShipJsonClassData”: {

“nation”: “usa”,

“shipIdNumber”: “4292753392”,

“shipTier”: 2,

“winRate”: “50.0”

},

“shipName”: “Sampson”

},

when I check the path for it there is an anonymous object that is represented in the path like this:
$.ships.[0]. I presume that anonymous object comes from the fact that I am passing a mutable list to the Array and it represents the index of that array.

I want to access the objects in this JSON but I do not know what syntax to use to access objects past that anonymous object.

jsonObject.getJSONObject([i]) for example does not work.

Suggestions on: A give that anonymous object a name on generation.

or B. how to access it would be greatly appreciated.

Thank you

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

Continue Reading Referencing nameless objects in a nested JSON

How Do I Convert My build.gradle.kts To Use The Multiplatform Module Instead Of The JVM One?


plugins { java val kotlinVersion: String by System.getProperties() kotlin("jvm").version(kotlinVersion) id("com.github.johnrengelman.shadow").version("6.0.0") } group = "com.smushytaco" version = "1.0.0" repositories { mavenCentral() maven("https://papermc.io/repo/repository/maven-public/") } dependencies { val kotlinVersion: String by System.getProperties() implementation(kotlin("stdlib", kotlinVersion)) implementation("org.rocksdb", "rocksdbjni", "6.11.4") //https://papermc.io/javadocs/paper/1.16/overview-summary.html compileOnly("com.destroystokyo.paper", "paper-api", "1.16.1-R0.1-SNAPSHOT") } tasks { shadowJar { archiveClassifier.set("") project.configurations.implementation.get().isCanBeResolved = true configurations = listOf(project.configurations.implementation.get()) relocate("kotlin", "com.smushytaco.src.main.kotlin") minimize() } build { dependsOn(shadowJar) } }

That’s the build.gradle.kts that uses the plain old jvm plugin module and I’m trying to convert it to use the multiplatform one in preparation of Kotlin 1.4 and this was my attempt at it:


plugins { java val kotlinVersion: String by System.getProperties() kotlin("multiplatform").version(kotlinVersion) id("com.github.johnrengelman.shadow").version("6.0.0") } kotlin { jvm() sourceSets { val jvmMain by getting { dependencies { val kotlinVersion: String by System.getProperties() implementation(kotlin("stdlib", kotlinVersion)) implementation("org.rocksdb:rocksdbjni:6.11.4") //https://papermc.io/javadocs/paper/1.16/overview-summary.html compileOnly("com.destroystokyo.paper:paper-api:1.16.1-R0.1-SNAPSHOT") } } } } group = "com.smushytaco" version = "1.0.0" repositories { mavenCentral() maven("https://papermc.io/repo/repository/maven-public/") } tasks { shadowJar { archiveClassifier.set("") project.configurations.implementation.get().isCanBeResolved = true configurations = listOf(project.configurations.implementation.get()) relocate("kotlin", "com.smushytaco.src.main.kotlin") minimize() } build { dependsOn(shadowJar) } }

This is very broken and doesn’t work. For starters it’s like the dependencies get ignored. With my MPP attempted build.gradle.kts whenever I go to my code there are errors everywhere because the dependencies aren’t properly build handled. Another issue I’m facing is the fact nothing is being shaded in the jars (Because dependencies are being ignored). The last issue I’m dealing with is that this MPP build.gradle.kts creates 3 jars instead of 1, before it just created Ride-1.0.0.jar but now it creates Ride-1.0.0.jar, Ride-jvm-1.0.0.jar, and Ride-metadata-1.0.0.jar. How do I fix all these issues?

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

Continue Reading How Do I Convert My build.gradle.kts To Use The Multiplatform Module Instead Of The JVM One?

KMP with Android and JVM

I’m trying to setup a project with three targets Android, JVM(Ktor) and JS.

Everything works fine when only JS and JVM targets are included , the moment I add android target, the JVM target can’t recognize anything from the common module but the android target can, and vice versa if I remove the android target.

Has anyone had this problem?

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

Continue Reading KMP with Android and JVM

I will code for your project (want experience)

Hi. If anyone has a project they are working on, I would like to contribute. I do not expect compensation, i simply want something meaningful to do and some real-world experience.

Edit: I was thinking of something like a personal/hobby project but if you are representing a commercial project, I would like to get paid appropriately. Thanks for the tip

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

Continue Reading I will code for your project (want experience)

ELI5: Nested for-loops

Hi guys, I’m currently learning Kotlin, it’s my first programming language – so I’m totally new to this.

Everything so far has made sense, and I’ve managed to figure it out, but this for-loop is driving me crazy!

fun main() {

for (i in 1..3) {

for (j in 1..i) {

print(j)

}

}

}

From the IDE, I know the print output is: 112123, but I cannot figure out why!

1..i should be 1, and i is 1..3 which is 123, so shouldn’t the output be 1231 or 1123?

Can someone please ELI5 this for me!

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

Continue Reading ELI5: Nested for-loops

End of content

No more pages to load