Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Studio Kotlin: Extract as Constant

In IntelliJ-based IDEs like Android Studio, in Java source codes, there is an option to extract things as constants when possible (final static). It is in Refactor -> Extract -> Constant and is accessible via Ctrl+Alt+C.

But I can't find it for Kotlin source codes!

enter image description here


Note 1: I can do it manually as you can see about NUMBER in the above screenshot (by defining it as a const val in companion object).

Note 2: The reverse-action is accomplishable by IDE; it means you can inline NUMBER with Ctrl+Alt+N.

like image 556
Mir-Ismaili Avatar asked Oct 25 '18 02:10

Mir-Ismaili


People also ask

How to Extract constant in Android Studio?

In IntelliJ-based IDEs like Android Studio, in Java source codes, there is an option to extract things as constants when possible ( final static ). It is in Refactor -> Extract -> Constant and is accessible via Ctrl + Alt + C .

What is constant in Android Studio?

Magic constants are a response to the ever-growing number of APIs in the Android framework, where the state, type of a component, or an action are chosen by providing an int or String constant. For example, setting view visibility with int constants or requiring a system service with String constants.

How do I create a constant in IntelliJ?

Press Ctrl+Alt+C to introduce a constant or select Refactor | Extract | Constant.


1 Answers

Unfortunately, this is a known missing feature for now. It's being tracked on the official issue tracker. You can vote for it there =)

like image 167
zsmb13 Avatar answered Sep 28 '22 03:09

zsmb13