简体   繁体   中英

Scala.Byte vs java.lang.Byte -Which one is recomended to use?

I was wondering which of the two possibilities is preferred. In my opinion they do more or less the same. What are the reasons why there are two implementation? Are there differences in the performance or functionality?

Use scala.Byte in most cases, because it corresponds to both byte and java.lang.Byte in Java terms and you usually want byte . The compiler will use byte for scala.Byte where it's possible/makes sense.

In my opinion they do more or less the same.

It's quite the same. Scala compiler compiles to Java bytecode, just like the Java compiler also compiles to JVM bytecode. A scala.Byte will therefore result in the same bytecode as the usage of java.lang.Byte .

What are the reasons why there are two implementation?

"Scala runs on the JVM, so Java and Scala stacks can be freely mixed for totally seamless integration." This is how Scala is described on https://www.scala-lang.org/ . So there are not really two implementations within Scala. You are just provided with the ability to use things from Java if you like / have to.

Are there differences in the performance or functionality

As mentioned above, you can consider them on byte code level as equal. However, they are at least diffrent in usage. If you write your Scala code like you would in Java, you can expect the same performance.

Which one is recomended to use?

If you can, use the Scala implementation. Simply because you'll not leave the "Scala world" and therefore benefit from potential improvements made by the language.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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