[jboss-cvs] javassist SVN: r553 - in trunk: tutorial and 1 other directory.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Thu Jul 8 14:17:04 EDT 2010


Author: chiba
Date: 2010-07-08 14:17:03 -0400 (Thu, 08 Jul 2010)
New Revision: 553

Modified:
   trunk/src/main/javassist/Modifier.java
   trunk/tutorial/tutorial3.html
Log:
fixed JIRA JASSIST-122

Modified: trunk/src/main/javassist/Modifier.java
===================================================================
--- trunk/src/main/javassist/Modifier.java	2010-07-08 11:01:36 UTC (rev 552)
+++ trunk/src/main/javassist/Modifier.java	2010-07-08 18:17:03 UTC (rev 553)
@@ -35,6 +35,7 @@
     public static final int FINAL     = AccessFlag.FINAL;
     public static final int SYNCHRONIZED = AccessFlag.SYNCHRONIZED;
     public static final int VOLATILE  = AccessFlag.VOLATILE;
+    public static final int VARARGS = AccessFlag.VARARGS;
     public static final int TRANSIENT = AccessFlag.TRANSIENT;
     public static final int NATIVE    = AccessFlag.NATIVE;
     public static final int INTERFACE = AccessFlag.INTERFACE;

Modified: trunk/tutorial/tutorial3.html
===================================================================
--- trunk/tutorial/tutorial3.html	2010-07-08 11:01:36 UTC (rev 552)
+++ trunk/tutorial/tutorial3.html	2010-07-08 18:17:03 UTC (rev 553)
@@ -24,8 +24,10 @@
 
 <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>
 
 <a name="intro">
@@ -294,8 +296,44 @@
 
 <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
 producing stack maps, which is similar to stack map tables introduced



More information about the jboss-cvs-commits mailing list