aboutsummaryrefslogtreecommitdiffstats
path: root/tutorial
diff options
context:
space:
mode:
authorchiba <chiba@30ef5769-5b8d-40dd-aea6-55b5d6557bb3>2007-05-12 14:45:10 +0000
committerchiba <chiba@30ef5769-5b8d-40dd-aea6-55b5d6557bb3>2007-05-12 14:45:10 +0000
commitc2d6bdf673d0fde9b947ae23094cd76493d5ca88 (patch)
treec0f5dbd5cbb7acf859f51b14ee7e08b4358e8aed /tutorial
parent4958b9a45ab284be8d5927d8cc96df14c64d02c1 (diff)
downloadjavassist-c2d6bdf673d0fde9b947ae23094cd76493d5ca88.tar.gz
javassist-c2d6bdf673d0fde9b947ae23094cd76493d5ca88.zip
changed the implementation of try statements so that jsr/ret will not be used anymore.
git-svn-id: http://anonsvn.jboss.org/repos/javassist/trunk@371 30ef5769-5b8d-40dd-aea6-55b5d6557bb3
Diffstat (limited to 'tutorial')
-rw-r--r--tutorial/tutorial.html2
-rw-r--r--tutorial/tutorial3.html65
2 files changed, 66 insertions, 1 deletions
diff --git a/tutorial/tutorial.html b/tutorial/tutorial.html
index 8776d8f8..8fe123cc 100644
--- a/tutorial/tutorial.html
+++ b/tutorial/tutorial.html
@@ -23,7 +23,7 @@ Shigeru Chiba
<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>
diff --git a/tutorial/tutorial3.html b/tutorial/tutorial3.html
index 657e629b..1c4afe73 100644
--- a/tutorial/tutorial3.html
+++ b/tutorial/tutorial3.html
@@ -22,6 +22,7 @@
</ul>
+<p><a href="#generics">6. Generics</a>
<p><br>
@@ -217,6 +218,70 @@ on those objects. For more details, see the javadoc manual
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>