简体   繁体   English

在Android Studio中反编译scala的.class文件会生成.java文件?

[英]Decompile scala's .class file in Android Studio generates .java file?

As first thing, I don't know Scala so well and neither .class files in details (from both java and scala). 首先,我不太了解Scala,也不太了解.class文件(来自Java和Scala)。

I'm porting Apache Flink on Android. 我正在Android上移植Apache Flink One of the libraries used in the project is flink-runtime.jar and contains this Scala file: 项目中使用的库之一是flink-runtime.jar ,其中包含以下Scala文件:

runtime/minicluster/LocalFlinkMiniCluster.scala

When Intellij IDEA decompile the LocalFlinkMiniCluster.class contained the .jar file, the correct and origal LocalFlinkMiniCluster.scala is displayed. 当Intellij IDEA反编译LocalFlinkMiniCluster.class包含.jar文件时,将显示正确且原始的LocalFlinkMiniCluster.scala

This doesn't happen in Android studio. 在Android Studio中不会发生这种情况。 Instead a java code is returned with the message : 而是随消息返回Java代码:

Decompiled .class file, bytecode version: 50.0 (Java 6) 反编译的.class文件,字节码版本:50.0(Java 6)

To make you understand better what I'm talking about, this is the method setMemory from the original .scala file: 为了使您更好地理解我在说什么,这是原始.scala文件中的setMemory方法:

  def setMemory(config: Configuration): Unit = {
    // set this only if no memory was pre-configured
    if (config.getInteger(ConfigConstants.TASK_MANAGER_MEMORY_SIZE_KEY, -1) == -1) {

      val bufferSize: Int = config.getInteger(
        ConfigConstants.TASK_MANAGER_MEMORY_SEGMENT_SIZE_KEY,
        ConfigConstants.DEFAULT_TASK_MANAGER_MEMORY_SEGMENT_SIZE)

      val bufferMem: Long = config.getLong(
        ConfigConstants.TASK_MANAGER_NETWORK_NUM_BUFFERS_KEY,
        ConfigConstants.DEFAULT_TASK_MANAGER_NETWORK_NUM_BUFFERS) * bufferSize.toLong

      val numTaskManager = config.getInteger(
        ConfigConstants.LOCAL_NUMBER_TASK_MANAGER,
        ConfigConstants.DEFAULT_LOCAL_NUMBER_TASK_MANAGER)

      val memoryFraction = config.getFloat(
        ConfigConstants.TASK_MANAGER_MEMORY_FRACTION_KEY,
        ConfigConstants.DEFAULT_MEMORY_MANAGER_MEMORY_FRACTION)

      // full memory size
      var memorySize: Long = EnvironmentInformation.getSizeOfFreeHeapMemoryWithDefrag

      // compute the memory size per task manager. we assume equally much memory for
      // each TaskManagers and each JobManager
      memorySize /= numTaskManager + 1 // the +1 is the job manager

      // for each TaskManager, subtract the memory needed for memory buffers
      memorySize -= bufferMem
      memorySize = (memorySize * memoryFraction).toLong
      memorySize >>>= 20 // bytes to megabytes
      config.setLong(ConfigConstants.TASK_MANAGER_MEMORY_SIZE_KEY, memorySize)
    }
  }

This is the java version created by Android Studio (what the hell is that asian symbol?): 这是由Android Studio创建的Java版本(亚洲符号到底是什么?):

public void setMemory(Configuration config) {
    if(config.getInteger("taskmanager.memory.size", -1) == -1) {
        int bufferSize = config.getInteger("taskmanager.memory.segment-size", '耀');
        long bufferMem = config.getLong("taskmanager.network.numberOfBuffers", 2048L) * (long)bufferSize;
        int numTaskManager = config.getInteger("local.number-taskmanager", 1);
        float memoryFraction = config.getFloat("taskmanager.memory.fraction", 0.7F);
        long memorySize = EnvironmentInformation.getSizeOfFreeHeapMemoryWithDefrag();
        memorySize /= (long)(numTaskManager + 1);
        memorySize -= bufferMem;
        memorySize = (long)((float)((double)memorySize * (double)memoryFraction));
        memorySize >>>= 20;
        config.setLong("taskmanager.memory.size", memorySize);
    }

}

And obviously the execution of the two methods have different effects. 显然,这两种方法的执行效果不同。

Please, can you help me to understand why this happens and how can I resolve this problem? 请,您能帮我了解为什么会发生这种情况以及如何解决此问题吗? Thanks. 谢谢。

I found out the problem by myself: the Scala plugin is installed by default (or there is an option anyway in the wizard) on IntelliJ. 我自己发现了问题:默认情况下,Scala插件是在IntelliJ上安装的(或者向导中始终有一个选项)。 In Android Studio instead it has to be installed manually. 而是必须在Android Studio中手动安装。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM