Kotlin basics 5. Keyword: const

const keyword
In addition to the val keyword to define a constant in Kotlin, a const keyword is also provided to identify a constant
const-modified val constant is equivalent to javastatic finalis the real java constant

The first step is to write kotlin code:

class MainActivity : AppCompatActivity() {
    
    
    companion object {
    
    
        const val REQUEST_CODE_TAKE_PHOTO = 101
        const val REQUEST_CODE_PICK_PHOTO = 102
    }
    ...

The second step, convert to Java code:
tools->Kotlin->show Kotlin Bytecode You can view the bytecode of the kotlin code

and then click Decompile in the upper right corner of the bytecode to convert the bytecode to java code, as shown in the figure:

The third Step, view the java code:

public final class MainActivity extends AppCompatActivity {
    
    
   private List pictures;
   private BaseQuickAdapter pictureAdapter;
   private Uri currentPictureUri;
   private File currentPictureFile;
   private final Set pictureAddressSet;
   public static final int REQUEST_CODE_TAKE_PHOTO = 101;
   public static final int REQUEST_CODE_PICK_PHOTO = 102;
   @NotNull
   public static final MainActivity.Companion Companion = new MainActivity.Companion((DefaultConstructorMarker)null);
   private HashMap _$_findViewCache;

   protected void onCreate(@Nullable Bundle savedInstanceState) {
    
    
      super.onCreate(savedInstanceState);
      this.setContentView(1300075);
      this.initListener();
      ...

At a glance, the code:

public static final int REQUEST_CODE_TAKE_PHOTO = 101;
public static final int REQUEST_CODE_PICK_PHOTO = 102;

Guess you like

Origin blog.csdn.net/qq_35091074/article/details/123505599