aboutsummaryrefslogtreecommitdiffstats
path: root/tutorial
diff options
context:
space:
mode:
authorchiba <chiba@30ef5769-5b8d-40dd-aea6-55b5d6557bb3>2010-07-08 18:17:03 +0000
committerchiba <chiba@30ef5769-5b8d-40dd-aea6-55b5d6557bb3>2010-07-08 18:17:03 +0000
commit0dfd78b0e5a50a9f3531d75a8543d8bdf54df24a (patch)
tree88f3101377e72eac856f81ab895111a27c57d8f1 /tutorial
parent066ce8b8722d191874c53870096d3cb2e1056f1d (diff)
downloadjavassist-0dfd78b0e5a50a9f3531d75a8543d8bdf54df24a.tar.gz
javassist-0dfd78b0e5a50a9f3531d75a8543d8bdf54df24a.zip
fixed JIRA JASSIST-122
git-svn-id: http://anonsvn.jboss.org/repos/javassist/trunk@553 30ef5769-5b8d-40dd-aea6-55b5d6557bb3
Diffstat (limited to 'tutorial')
-rw-r--r--tutorial/tutorial3.html42
1 files changed, 40 insertions, 2 deletions
diff --git a/tutorial/tutorial3.html b/tutorial/tutorial3.html
index 17e21410..9b281a13 100644
--- a/tutorial/tutorial3.html
+++ b/tutorial/tutorial3.html
@@ -24,7 +24,9 @@
<p><a href="#generics">6. Generics</a>
-<p><a href="#j2me">7. J2ME</a>
+<p><a href="#varargs">7. Varargs</a>
+
+<p><a href="#j2me">8. J2ME</a>
<p><br>
@@ -294,7 +296,43 @@ public Object get() { return value; }
<p><br>
-<h2><a name="j2me">7. J2ME</a></h2>
+<h2><a name="varargs">7. Varargs</a></h2>
+
+<p>Currently, Javassist does not directly support varargs. So to make a method with varargs,
+you must explicitly set a method modifier. But this is easy.
+Suppose that now you want to make the following method:
+
+<ul><pre>
+public int length(int... args) { return args.length; }
+</pre></ul>
+
+<p>The following code using Javassist will make the method shown above:
+
+<ul><pre>
+CtClass cc = /* target class */;
+CtMethod m = CtMethod.make("public int length(int[] args) { return args.length; }", cc);
+m.setModifiers(m.getModifiers() | Modifier.VARARGS);
+cc.addMethod(m);
+<pre></ul>
+
+<p>The parameter type <code>int...</code> is changed into <code>int[]</code>
+and <code>Modifier.VARARGS</code> is added to the method modifiers.
+
+<p>To call this method, you must write:
+
+<ul><pre>
+length(new int[] { 1, 2, 3 });
+</pre></ul>
+
+<p>instead of this method call using the varargs mechanism:
+
+<ul><pre>
+length(1, 2, 3);
+</pre></ul>
+
+<p><br>
+
+<h2><a name="j2me">8. J2ME</a></h2>
<p>If you modify a class file for the J2ME execution environment,
you must perform <it>preverification</it>. Preverifying is basically