tutorial-Other-Java-features.xhtml 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?xml version="1.0" encoding="UTF-8" standalone="no"?>
  2. <!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:pls="http://www.w3.org/2005/01/pronunciation-lexicon" xmlns:ssml="http://www.w3.org/2001/10/synthesis" xmlns:svg="http://www.w3.org/2000/svg">
  3. <head>
  4. <title>Other Java features</title>
  5. <link rel="stylesheet" type="text/css" href="docbook-epub.css"/>
  6. <link rel="stylesheet" type="text/css" href="kawa.css"/>
  7. <script src="kawa-ebook.js" type="text/javascript"/>
  8. <meta name="generator" content="DocBook XSL-NS Stylesheets V1.79.1"/>
  9. <link rel="prev" href="tutorial-Classes.xhtml" title="Classes"/>
  10. <link rel="next" href="pt01.xhtml" title="Part . Reference Documentation"/>
  11. </head>
  12. <body>
  13. <header/>
  14. <section class="sect1" title="Other Java features" epub:type="subchapter" id="Tutorial---Other-Java-features">
  15. <div class="titlepage">
  16. <div>
  17. <div>
  18. <h2 class="title" style="clear: both">Other Java features</h2>
  19. </div>
  20. </div>
  21. </div>
  22. <h3 id="idm139667880338016">Import</h3>
  23. <p>The <code class="literal">import</code> form can be used to avoid having to write
  24. fully-qualified class names. For example:
  25. </p>
  26. <pre class="screen">(import (class java.util
  27. Map
  28. (HashMap HMap)))
  29. </pre>
  30. <p>This defines aliases for two classes in the <code class="literal">java.util</code> package,
  31. one with renaming:
  32. <code class="literal">Map</code> is an alias for <code class="literal">java.util.Map</code>,
  33. and <code class="literal">HMap</code> is an alias for <code class="literal">java.util.HashMap</code>.
  34. </p>
  35. <p>The <code class="literal">class</code> keyword is needed because the <code class="literal">import</code>
  36. form is also used for Kawa’s module system.
  37. See <a class="link" href="FAQs.xhtml#importing-class-names">importing-class-names</a> and <a class="link" href="Importing.xhtml" title="Importing from a library">Importing</a> for details.
  38. </p>
  39. <h3 id="idm139667880330784">Synchronized blocks</h3>
  40. <p>You can use a <code class="literal">synchronized</code> expression:
  41. </p>
  42. <pre class="screen">(synchronized obj form1 ... formn)
  43. </pre>
  44. <p>This waits until it can get an exclusive lock on <em class="replaceable"><code>obj</code></em>
  45. and then evaluates <em class="replaceable"><code>form1</code></em> through <em class="replaceable"><code>formn</code></em>.
  46. Unlike Java, this is an expression and returns the value of <em class="replaceable"><code>formn</code></em>.
  47. </p>
  48. <h3 id="idm139667880326704">Annotations</h3>
  49. <p>You can write annotation declarations - see <a class="link" href="Annotations.xhtml" title="Annotations of declarations">Annotations</a> for details.
  50. </p>
  51. <p>Kawa does not yet support annotations on types,
  52. or declaring new annotation classes.
  53. </p>
  54. </section>
  55. <footer>
  56. <div class="navfooter">
  57. <p>
  58. Up: <a accesskey="u" href="tutorial-index.xhtml">Kawa Scheme Tutorial</a></p>
  59. <p>
  60. Previous: <a accesskey="p" href="tutorial-Classes.xhtml">Classes</a></p>
  61. </div>
  62. </footer>
  63. </body>
  64. </html>