/www/tags/NOV_07_2009/htdocs/42docs/users-guide/dynamic-typing.html
HTML | 34 lines | 32 code | 2 blank | 0 comment | 0 complexity | a0be54ee9fd8e675ba68319d52ef3839 MD5 | raw file
Possible License(s): BSD-3-Clause, AGPL-1.0, Apache-2.0, LGPL-2.0, LGPL-3.0, GPL-2.0, CC-BY-SA-3.0, LGPL-2.1, GPL-3.0, MPL-2.0-no-copyleft-exception, IPL-1.0
- <html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>BeanShell Dynamic Typing</title><meta name="generator" content="DocBook XSL Stylesheets V1.65.1"><link rel="home" href="index.html" title="jEdit 4.2 User's Guide"><link rel="up" href="macro-basics.html" title="Chapter 13. Macro Basics"><link rel="previous" href="helpful-methods.html" title="Helpful Methods in the
- Macros Class"><link rel="next" href="something-useful.html" title="Now For Something Useful"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">BeanShell Dynamic Typing</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="helpful-methods.html">Prev</a> </td><th width="60%" align="center">Chapter 13. Macro Basics</th><td width="20%" align="right"> <a accesskey="n" href="something-useful.html">Next</a></td></tr></table><hr></div><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="dynamic-typing"></a>BeanShell Dynamic Typing</h2></div></div><div></div></div><p>
- Without an explicit <i class="glossterm">type declaration</i> like
- <tt class="classname">String</tt> <tt class="varname">result</tt>, BeanShell
- variables can change their type at runtime depending on the object or
- data assigned to it. This dynamic typing allows you to write code like
- this (if you really wanted to):
- </p><div class="informalexample"><table border="0" bgcolor="#E0E0E0"><tr><td><pre class="programlisting">// note: no type declaration
- result = Macros.input(view, “<span class="quote">Type something here.</span>”);
- // this is our predefined, current View
- result = view;
- // this is an “<span class="quote">int</span>” (for integer);
- // in Java and BeanShell, int is one of a small number
- // of “<span class="quote">primitive</span>” data types which are not classes
- result = 14;</pre></td></tr></table></div><p>
- However, if you first declared <tt class="varname">result</tt> to be type
- <tt class="classname">String</tt> and and then tried these reassignments,
- BeanShell would complain. While avoiding explicit type declaration makes
- writing macro code simpler, using them can act as a check to make sure you are
- not using the wrong variable type of object at a later point in your
- script. It also makes it easier (if you are so inclined) to take a
- BeanShell “<span class="quote">prototype</span>” and incorporate it in a Java program.
- </p><p>
- One last thing before we bury our first macro. The double slashes in the
- examples just above signify that everything following them on that line
- should be ignored by BeanShell as a comment. As in Java and C/C++, you
- can also embed comments in your BeanShell code by setting them off with
- pairs of <b class="userinput"><tt>/* */</tt></b>, as in the following example:
- </p><div class="informalexample"><table border="0" bgcolor="#E0E0E0"><tr><td><pre class="programlisting">/* This is a long comment that covers several lines
- and will be totally ignored by BeanShell regardless of how
- many lines it covers */</pre></td></tr></table></div></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="helpful-methods.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="macro-basics.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="something-useful.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">Helpful Methods in the
- Macros Class </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> Now For Something Useful</td></tr></table></div></body></html>