In this article we are going to do a crash course on Go’s interfaces, then in the rest of this series we will continue exploring how interfaces work, how to use them effectively, and more.
In Go there are both arrays and slices. This can be confusing at first, but once you get used to it you will love it. Trust me. There are many differences between slices and arrays, but the primary one we want to focus on in this article is that the size of an array is part of its type, whereas slices can have a dynamic…
Conversion between numeric types There are three most common numeric types: Int, Long, and Double. Sometimes, you may need to assign a value of one numeric type to a variable of another numeric type. In this case, you need to carry out type conversion by invoking a special function, for example, toInt(), toLong(), toDouble(), and so on.
In this topic, we will learn about the classification and properties of basic types in Kotlin. You may know some of them. Basic types can be separated into several groups according to their meaning. The types from the same group operate similarly, but they have different sizes and, as a consequence, represent different ranges of values.
What is a data type? All of us know that a number and a piece of text are pretty different. How do we know this? Well, you can perform arithmetic operations (such as multiplication) on numbers but not on texts. Kotlin also knows it. That’s why every variable has a type that determines what possible operations you can perform on this variable and which values you can…
You already know that objects are really complex structures and variables only point to objects. This time, you will learn about equality and how to understand that variables point to the same object. In addition, you will finally fully understand the meaning of the val keyword and avoid one of the most common beginner mistakes: assuming that the val keyword guarantees immutability.
Everything is an object In our life, we are always surrounded by objects: you drive a car, watch TV, read books, pay for bananas with your smartphone. In Kotlin, every time when you work with variables, you work with objects. For example, an integer 5 and a string “love” are objects. It is convenient because programmers are people, and people are used to dealing with objects.…
Sometimes, you need to use a variable that should not be modified during the program execution. Such variables are known as constants, or val variables in Kotlin, where they are declared with the val keyword. The difference between a var variable and a val variable is that we cannot modify the value of a val variable once assigned.
What is a variable? A variable is a storage for a value, which can be a string, a number, or something else. Every variable has a name (or an identifier) to distinguish it from other variables. You can access a value by the name of the variable.
Kotlin String templates are a powerful tool for formatting strings. However, they have limitations, especially when one wants to print numerical values. Here, the String format() member function comes into play, which provides much more flexibility.