Small knowledge, big challenge! This article is participating in the creation activity of “Essential Tips for Programmers”.

👉 About the author

As we all know, life is a long process of constantly overcoming difficulties and reflecting on progress. In this process, there will be a lot of questions and thoughts about life, so I decided to share my thoughts, experiences and stories to find resonance!!

Focus on Android/Unity and various game development tips, as well as various resource sharing (websites, tools, materials, source code, games, etc.)

Welcome to pay attention to the public account [Mr. Empty name] for more resources and communication!

👉 premise

The current environment

2020.3.1 Patch 2 version was last downloaded on October 8, 2021

👉 Practice

😜 Get and Set

After Kotlin declares the entity class, the variables in the entity class are set and GET properties by default. Unless you want specific business content.

For example, a set needs to be combined with a project for other business processes, and the same is true for GET.

[Filed] is a keyword built into the system, which is an intermediate variable

In addition to these

var name: String? = null
        set(value) { //value any name you want
            field = value  // This field is built-in for get
        }
        get() {
            return field + "This is the return."
        }
var urlJUEJIIN: String? = null
        get(a) =field+"This is only get."
var urlCSDN: String? = null
var urlList: List<String>? = null
Copy the code

😜 inheritance

Whereas in Java you can say that all classes inherit from Object, in Kotlin you can say that all classes inherit from Any.

The extends keyword is inherited in Java, while Kotlin uses: (colon)

In addition, both method overrides and attribute variable overrides are preceded by the [override] keyword, just like in Java

class EntityTwo : Entity {
    constructor() {

    }

    constructor(name: String) : this(name, 0) {}// Secondary constructors for different arguments
    constructor(name: String, age: Int) : super(name, age) {
        Log.e("TAG,".Subclass constructor $name===$age)}}Copy the code

😜 interface

This is also similar to Java, using the interface definition, there is no difference in use

The keywords of the modifier class are

  • Abstract // indicates that this class is abstract
  • Final // Indicates that the class is not inheritable and is the default property
  • Enum // Note This class is an enumeration class
  • Open // Indicates that the class is inheritable and final by default
  • Annotation // Indicate that this class is an annotation class

Modifiers for access permissions are:

  • Private // Access – Visible only in the same file
  • Protected // Access rights – visible in the same file or subclass
  • Public // Access permissions – All calls are visible
  • Internal // Access permissions – visible in the same module

After learning and experimenting, Okura decided to use Java entity classes, which have interoperability anyway.

😜 Abstract/nested/inner class

Small empty belt we directly with example to see understand

abstract class EntityThree {
    abstract fun methonOne(a)
}

// Nested class instances
class One {                  // This is an external class
    private val age: Int = 1
    class Two {             // This is a class inside a class, called a nested class
        fun hello(a) {}fun hi(a) = 3}}// Inner classes use the keyword inner
class Three {
    inner class Four { // This Four class is an inner class
        fun hello(a) {}fun hi(a) = 3}}// This is a reference example
var one = Three().Four().hello()
Copy the code

👉 other

📢 author: Kom and Kom in Kom

📢 reprint instructions – be sure to specify the source: Zhim Granular’s personal home page – column – Nuggets (juejin. Cn)

📢 welcome to like 👍 collect 🌟 message 📝