Focusing Hint EditText: A Picky requirement from UI Designer
Let’s say you already know about getter and setter of Java.
The Accessors are like this:
class Pizza {
private int radius;
public void setRadius(int radius) {
this.radius = radius;
}
public int getRadius() {
return radius;
}
}
In Kotlin, it is really simple!
class Pizza(var radius: Int)
That’s it! It is same with above Java code.
property radius
makes itself getter and setter internally.(If you want to make only getter, val radius: Int
)
Let’s define ‘large size’ if its radius longer than 20.
To check if a pizza is large size or not, you could add a property like val isLargeSize: Boolean = true
or val isLargeSize: Boolean = false
But Custom Accessor makes it even more simple.
class Pizza(var radius: Int) {
val isLargeSize get() = radius>20
}
It doesn’t need field that save its value. Getter calculate isLargeSize
everytime client access to the property.
Moreover you can use this for some util function.
val Int.isEven get() = this%2==0
val String.hasUpperCase: Boolean get() {
this.forEach {
if(it.isUpperCase()) return true
}
return false
}
//usage
println("Is 6 even number? ${6.isEven}") //true
println("macbook has uppercase? ${"macbook".hasUpperCase}" //false
If there’s a mistake, always welcome your opinion!
</br>
Last month, Jetpack Compose Beta was released! see Beta Overview Even if it’s beta, looks cool for some super advantages. In this posting, I will focus on L...
No doubt about that Clubhouse is the most hottest social media recently. There is no special UI/UX which is never have seen anywhere else. But I’m impressed ...
Almost every Android developers have tried passing data and getting response between two activities. Before Result API released, we passed data on startActi...
Let’s say you already know about getter and setter of Java. The Accessors are like this:
No doubt about that Clubhouse is the most hottest social media recently. There is no special UI/UX which is never have seen anywhere else. But I’m impressed ...
Last month, Jetpack Compose Beta was released! see Beta Overview Even if it’s beta, looks cool for some super advantages. In this posting, I will focus on L...