diff options
author | Li Haoyi <haoyi@dropbox.com> | 2015-03-12 20:13:25 +0800 |
---|---|---|
committer | Li Haoyi <haoyi@dropbox.com> | 2015-03-28 22:11:38 +0800 |
commit | 7006cebd061784900233c405ce03665151b86010 (patch) | |
tree | 5809b127984508a436f6806d94132c29ea2b8fee /book/src/main/scalatex/book/indepth/JavaAPIs.scalatex | |
parent | ac86ffc25a169585fffffd2535e856b9826e78ad (diff) | |
download | hands-on-scala-js-7006cebd061784900233c405ce03665151b86010.tar.gz hands-on-scala-js-7006cebd061784900233c405ce03665151b86010.tar.bz2 hands-on-scala-js-7006cebd061784900233c405ce03665151b86010.zip |
better scrolling
Diffstat (limited to 'book/src/main/scalatex/book/indepth/JavaAPIs.scalatex')
-rw-r--r-- | book/src/main/scalatex/book/indepth/JavaAPIs.scalatex | 46 |
1 files changed, 0 insertions, 46 deletions
diff --git a/book/src/main/scalatex/book/indepth/JavaAPIs.scalatex b/book/src/main/scalatex/book/indepth/JavaAPIs.scalatex deleted file mode 100644 index 1a0afa5..0000000 --- a/book/src/main/scalatex/book/indepth/JavaAPIs.scalatex +++ /dev/null @@ -1,46 +0,0 @@ -@import BookData._ - -@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. @lnk("Scala.Rx", "https://github.com/lihaoyi/scala.rx") that need them. - -@sect{Available Java APIs} - - @ul - @for(data <- BookData.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 @lnk("OpenJDK", "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 @lnk("Harmony", "http://harmony.apache.org/") - @li - Submit a pull-request to the @lnk("Scala.js repository", "https://github.com/scala-js/scala-js"), including your implementation, together with tests. See the @lnk("existing tests", "https://github.com/scala-js/scala-js/tree/master/test-suite/src/test/scala/org/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. For example, @hl.scala{AtomicXXXs} can be written without threading/unsafe APIs because Javascript is single-threaded, making the implementation for e.g. an @hl.scala{AtomicBoolean} pretty trivial: - - @hl.ref(cloneRoot/"scala-js"/'javalib/'src/'main/'scala/'java/'util/'concurrent/'atomic/"AtomicBoolean.scala") - - @p - Others can't be ported at all (e.g. @code{java.io.File}) simply because the API capabilities they provide (blocking reads & writes to files) do not exist in the Javascript runtime. - |