diff options
author | Li Haoyi <haoyi@dropbox.com> | 2014-11-09 10:08:47 -0800 |
---|---|---|
committer | Li Haoyi <haoyi@dropbox.com> | 2014-11-09 10:08:47 -0800 |
commit | 978a138c02c07822ef71f31f71e552a9659a0a53 (patch) | |
tree | 9771e4d4620af7e6f5ff54cb4c711e04cffb4e30 /book/src/main/scalatex/book/indepth/JavaAPIs.scalatex | |
parent | 795c0eb5de003b22c3874762557ae2b34ae64de0 (diff) | |
download | hands-on-scala-js-978a138c02c07822ef71f31f71e552a9659a0a53.tar.gz hands-on-scala-js-978a138c02c07822ef71f31f71e552a9659a0a53.tar.bz2 hands-on-scala-js-978a138c02c07822ef71f31f71e552a9659a0a53.zip |
wip
Diffstat (limited to 'book/src/main/scalatex/book/indepth/JavaAPIs.scalatex')
-rw-r--r-- | book/src/main/scalatex/book/indepth/JavaAPIs.scalatex | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/book/src/main/scalatex/book/indepth/JavaAPIs.scalatex b/book/src/main/scalatex/book/indepth/JavaAPIs.scalatex new file mode 100644 index 0000000..89f0a57 --- /dev/null +++ b/book/src/main/scalatex/book/indepth/JavaAPIs.scalatex @@ -0,0 +1,38 @@ +@p + Below is a list of classes from the Java Standard Library that are available from Scala.js. In general, much of @hl.scala{java.lang}, and parts of @hl.scala{java.io}, @hl.scala{java.util} and @hl.scala{java.net} have been ported over. This means that all these classes are available for use in Scala.js applications despite being part of the Java standard library. +@p + There are many reasons you may want to port a Java class to Scala.js: you want to use it directly, you may be trying to port a library which uses it. In general, we haven't been porting things "for fun", and obscure classes like @hl.scala{org.omg.corba} will likely never be ported: we've been porting things as the need arises in order to support libraries (e.g. @a("Scala.Rx", href:="https://github.com/lihaoyi/scala.rx") that need them. + +@sect{Available Java APIs} + + @ul + @for(data <- Book.javaAPIs) + @li + @a(data._1, href:=data._2) + +@sect{Porting Java APIs} + @p + The process for making Java library classes available in Scala.js is relatively straightforward: + @ul + @li + Find a class that you want to use in Scala.js, but is not implemented. + @li + Write a clean-room implementation in Scala, without looking at the source code of @a("OpenJDK", href:="http://openjdk.java.net/"). This is due to legal-software-license incompatibility between OpenJDK and Scala.js. Reading the docs or specification are fine, as is looking at the source of alternate implementations such as @a("Harmony", href:="http://harmony.apache.org/") + @li + Submit a pull-request to the @a("Scala.js repository", href:="https://github.com/scala-js/scala-js"), including your implementation, together with tests. See the @a("existing tests", href:="https://github.com/scala-js/scala-js/tree/master/test-suite/src/test/scala/scala/scalajs/testsuite/javalib") in the repository if you need examples of how to write your own. + + @p + In general, this is a simple process, for "pure-Java" classes which do not use any special JVM/Java-specific APIs. However, this will not be possible for classes which do! This means that classes that make use of Java-specific things like: + + @ul + @li + Threads + @li + Filesystem APIs + @li + Network APIs + @li + @hl.scala{sun.misc.Unsafe} + + @p + And other similar APIs will either need to be rewritten to not-use them (e.g. @a("AtomicIntegers", href:="https://github.com/scala-js/scala-js/blob/master/javalib/src/main/scala/java/util/concurrent/atomic/AtomicInteger.scala") can be written without threading/unsafe APIs because Javascript is single-threaded) or can't be ported at all (e.g. @code{java.io.File})
\ No newline at end of file |