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

时间:2016-03-23 08:49:23

标签: java android scala

首先,我不太了解Scala,也没有详细说明.class文件(来自java和scala)。

我在Android上移植Apache Flink。该项目中使用的库之一是flink-runtime.jar并包含此Scala文件:

runtime/minicluster/LocalFlinkMiniCluster.scala

当Intellij IDEA反编译包含LocalFlinkMiniCluster.class文件的.jar时,会显示正确且原始的LocalFlinkMiniCluster.scala

在Android工作室中不会发生这种情况。而是返回一个带有消息的java代码:

  

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

为了让您更好地理解我正在谈论的内容,这是来自原始.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)
    }
  }

这是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);
    }

}

显然,这两种方法的执行有不同的效果。

拜托,您能帮我理解为什么会这样,我该如何解决这个问题?谢谢。

1 个答案:

答案 0 :(得分:0)

我自己发现了这个问题:默认情况下安装了Scala插件(或者在向导中有一个选项)IntelliJ。在Android Studio中,它必须手动安装。