[jboss-cvs] javassist/tutorial ...

Shigeru Chiba chiba at is.titech.ac.jp
Sat May 12 10:45:09 EDT 2007


  User: chiba   
  Date: 07/05/12 10:45:09

  Modified:    tutorial   tutorial3.html tutorial.html
  Log:
  changed the implementation of try statements so that jsr/ret will not be used anymore.
  
  Revision  Changes    Path
  1.8       +65 -0     javassist/tutorial/tutorial3.html
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: tutorial3.html
  ===================================================================
  RCS file: /cvsroot/jboss/javassist/tutorial/tutorial3.html,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -b -r1.7 -r1.8
  --- tutorial3.html	20 Jun 2005 17:08:10 -0000	1.7
  +++ tutorial3.html	12 May 2007 14:45:09 -0000	1.8
  @@ -22,6 +22,7 @@
   
   </ul>
   
  +<p><a href="#generics">6. Generics</a>
   
   <p><br>
   
  @@ -217,6 +218,70 @@
   of <code>javassist.bytecode.AnnotationsAttribute</code> class
   and the <code>javassist.bytecode.annotation</code> package.
   
  +<p>Javassist also let you access annotations by the higher-level
  +API.
  +If you want to access annotations through <code>CtClass</code>,
  +call <code>getAnnotations()</code> in <code>CtClass</code> or
  +<code>CtBehavior</code>.
  +
  +<p><br>
  +
  +<h2><a name="generics">6. Generics</a></h2>
  +
  +<p>The lower-level API of Javassist fully supports generics
  +introduced by Java 5.  On the other hand, the higher-level
  +API such as <code>CtClass</code> does not directly support
  +generics.  However, this is not a serious problem for bytecode
  +transformation.
  +
  +<p>The generics of Java is implemented by the erasure technique.
  +After compilation, all type parameters are dropped off.  For
  +example, suppose that your source code declare a parameterized
  +type <code>Vector&lt;String&gt;</code>:
  +
  +<ul><pre>
  +Vector&lt;String&gt; v = new Vector&lt;String&gt();
  +  :
  +String s = v.get(0);
  +</pre></ul>
  +
  +<p>The compiled bytecode is equivalent to the following code:
  +
  +<ul><pre>
  +Vector v = new Vector();
  +  :
  +String s = (String)v.get(0);
  +</pre></ul>
  +
  +<p>So when you write a bytecode transformer, you can just drop
  +off all type parameters.  For example, if you have a class:
  +
  +<ul><pre>
  +public class Wrapper&lt;T&gt; {
  +  T value;
  +  public Wrapper(T t) { value = t; }
  +}
  +</pre></ul>
  +
  +<p>and want to add an interface <code>Getter&lt;T&gt;</code> to the
  +class <code>Wrapper&lt;T&gt;</code>:
  +
  +<ul><pre>
  +public interface Getter&lt;T&gt; {
  +  T get();
  +}
  +</pre></ul>
  +
  +<p>Then the interface you really have to add is <code>Getter</code>
  +(the type parameters <code>&lt;T&gt;<code> drops off)
  +and the method you also have to add to the <code>Wrapper</code>
  +class is this simple one:
  +
  +<ul><pre>
  +public Object get() { return value; }
  +</pre></ul>
  +
  +<p>Note that no type parameters are necessary.
   
   <p><br>
   
  
  
  
  1.30      +1 -1      javassist/tutorial/tutorial.html
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: tutorial.html
  ===================================================================
  RCS file: /cvsroot/jboss/javassist/tutorial/tutorial.html,v
  retrieving revision 1.29
  retrieving revision 1.30
  diff -u -b -r1.29 -r1.30
  --- tutorial.html	1 Jul 2006 02:13:08 -0000	1.29
  +++ tutorial.html	12 May 2007 14:45:09 -0000	1.30
  @@ -23,7 +23,7 @@
   <br>3. <a href="#load">Class loader</a>
   <br>4. <a href="tutorial2.html#intro">Introspection and customization</a>
   <br>5. <a href="tutorial3.html#intro">Bytecode level API</a>
  -
  +<br>6. <a href="tutorial3.html#generics">Generics</a>
   </ul>
   
   <p><br>
  
  
  



More information about the jboss-cvs-commits mailing list