From c2d6bdf673d0fde9b947ae23094cd76493d5ca88 Mon Sep 17 00:00:00 2001 From: chiba Date: Sat, 12 May 2007 14:45:10 +0000 Subject: 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 --- tutorial/tutorial.html | 2 +- tutorial/tutorial3.html | 65 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+), 1 deletion(-) (limited to 'tutorial') 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
3. Class loader
4. Introspection and customization
5. Bytecode level API - +
6. Generics


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 @@ +

6. Generics


@@ -217,6 +218,70 @@ on those objects. For more details, see the javadoc manual of javassist.bytecode.AnnotationsAttribute class and the javassist.bytecode.annotation package. +

Javassist also let you access annotations by the higher-level +API. +If you want to access annotations through CtClass, +call getAnnotations() in CtClass or +CtBehavior. + +


+ +

6. Generics

+ +

The lower-level API of Javassist fully supports generics +introduced by Java 5. On the other hand, the higher-level +API such as CtClass does not directly support +generics. However, this is not a serious problem for bytecode +transformation. + +

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 Vector<String>: + +

+ +

The compiled bytecode is equivalent to the following code: + +

+ +

So when you write a bytecode transformer, you can just drop +off all type parameters. For example, if you have a class: + +

+ +

and want to add an interface Getter<T> to the +class Wrapper<T>: + +

+ +

Then the interface you really have to add is Getter +(the type parameters <T> drops off) +and the method you also have to add to the Wrapper +class is this simple one: + +

+ +

Note that no type parameters are necessary.


-- cgit v1.2.3