Update from Forestry.io
Harsh Shandilya updated content/posts/teachingkotlin-part-1-classes-and-objects-and-everything-in-between.md
This commit is contained in:
parent
5d2e7e3fef
commit
043f7463ba
|
@ -7,3 +7,28 @@ tags = ["android", "teachingkotlin", "kotlin"]
|
|||
title = "#TeachingKotlin Part 1 - Classes and Objects and everything in between"
|
||||
|
||||
+++
|
||||
Classes in Kotlin closely mimic their Java counterparts in implementation, with some crucial changes that I will attempt to outline here.
|
||||
|
||||
Let's declare two identical classes in Kotlin and Java as a starting point. We'll be making changes to them alongside to show how different patterns are implemented in the two languages.
|
||||
|
||||
\`\`\`java
|
||||
|
||||
class Example {
|
||||
|
||||
private final String name;
|
||||
|
||||
Example(String name) {
|
||||
|
||||
this.name = name;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
\`\`\`
|
||||
|
||||
\`\`\`kotlin
|
||||
|
||||
class Example(val name: String)
|
||||
|
||||
\`\`\`
|
Loading…
Reference in New Issue