Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Kotlin: Why are most variables underlined in Android Studio and how do I turn that off?

I wanted to know why most variables in Kotlin are underlined. Some files contain a lot of underlining which is very annoying. If I hover my mouse over a variable it doesn't give any information most of the time. But on some it says "This property has a backing field" or "Value captured in a closure". Does anybody know how to disable those underlines? Here is a screenshot with what I mean: enter image description here

And realm is then underlined throughout the entire file.

like image 345
Kevin van Mierlo Avatar asked Jan 23 '16 13:01

Kevin van Mierlo


People also ask

Why is a variable underlined in Android Studio?

To protect your variable from the side effect, the IDE shows the underline as a warning to you. Which is sometimes very helpful to reduce logical bugs in your code.

Why is my variable underlined in Intellij?

If the variable/parameter is underlined, you know that you can't use it in lambda/anonymous class directly.

How do I set the variable type in Kotlin?

Kotlin uses two different keywords to declare variables: val and var . Use val for a variable whose value never changes. You can't reassign a value to a variable that was declared using val . Use var for a variable whose value can change.

What does variable mean in Kotlin?

Variables are containers for storing data values. To create a variable, use var or val , and assign a value to it with the equal sign ( = ):


2 Answers

It's just Editor Preferences.

Edit:

This is moved to

Preferences -> Editor -> Color Scheme -> Kotlin -> Properties and Variables 

enter image description here

Thanks rmirabelle for the comment

For the old plugin, you can go to

Preferences -> Editor -> Color Scheme -> Kotlin 

Then find Var (mutable variable, parameter or property) and remove Underscored effect.

I guess they just try to discourage using var by adding the annoying underscored. :P

old plugin

like image 179
pt2121 Avatar answered Sep 30 '22 11:09

pt2121


In Android Studio 3.1.2 this has been moved to -

Settings > Editor > Color Scheme > Kotlin

enter image description here

like image 36
Hrishikesh Kadam Avatar answered Sep 30 '22 11:09

Hrishikesh Kadam