From: chibash Date: Mon, 16 Jun 2014 03:52:31 +0000 (+0900) Subject: updated the tutorial for JASSIST-225 X-Git-Tag: rel_3_19_0_ga~23 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=ae7b93b7b7466616ad3b8f4313c27271dc2ee38d;p=javassist.git updated the tutorial for JASSIST-225 --- diff --git a/tutorial/tutorial.html b/tutorial/tutorial.html index f7bb622a..95da0729 100644 --- a/tutorial/tutorial.html +++ b/tutorial/tutorial.html @@ -1100,6 +1100,6 @@ For more information, see the API documentation of
Java(TM) is a trademark of Sun Microsystems, Inc.
-Copyright (C) 2000-2012 by Shigeru Chiba, All rights reserved. +Copyright (C) 2000-2014 by Shigeru Chiba, All rights reserved. diff --git a/tutorial/tutorial2.html b/tutorial/tutorial2.html index b3a61e7b..f2571c8b 100644 --- a/tutorial/tutorial2.html +++ b/tutorial/tutorial2.html @@ -1563,9 +1563,12 @@ has several limitations with respect to the language that the compiler can accept. Those limitations are:

  • The new syntax introduced by J2SE 5.0 (including enums and generics) -has not been supported. Annotations are supported only by the low level +has not been supported. Annotations are supported by the low level API of Javassist. -See the javassist.bytecode.annotation package. +See the javassist.bytecode.annotation package +(and also getAnnotations() +in CtClass and CtBehavior). +Generics are also only partly supported. See the latter section for more details.

  • Array initializers, a comma-separated list of expressions enclosed by braces { and }, are not @@ -1625,6 +1628,6 @@ write:
    Java(TM) is a trademark of Sun Microsystems, Inc.
    -Copyright (C) 2000-2010 by Shigeru Chiba, All rights reserved. +Copyright (C) 2000-2014 by Shigeru Chiba, All rights reserved. diff --git a/tutorial/tutorial3.html b/tutorial/tutorial3.html index 7c505e0b..e6964553 100644 --- a/tutorial/tutorial3.html +++ b/tutorial/tutorial3.html @@ -269,7 +269,15 @@ String s = (String)v.get(0);

    So when you write a bytecode transformer, you can just drop -off all type parameters. For example, if you have a class: +off all type parameters. Because the compiler embedded in Javassist +does not support generics, +you must insert an explicit type cast at the +caller site if the source code is compiled by Javassist, for example, +through CtMethod.make(). No type cast +is necessary if the source code is compiled by a normal Java compiler +such as javac. + +

    For example, if you have a class:

    -

    Then the interface you really have to add is Getter +

    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: @@ -297,8 +305,20 @@ public Object get() { return value; }

    Note that no type parameters are necessary. +Since get returns an Object, an explicit type cast +is needed at the caller site if the source code is compiled by Javassist. +For example, if the type parameter T +is String, then (String) must be inserted as follows: + +

    + +

    The type cast is not needed if the source code is compiled by a normal Java +compiler because it will automatically insert a type cast. -

    However, if you need to make type parameters accessible through reflection +

    If you need to make type parameters accessible through reflection during runtime, you have to add generic signatures to the class file. For more details, see the API documentation (javadoc) of the setGenericSignature method in the CtClass. @@ -327,7 +347,8 @@ cc.addMethod(m);

    The parameter type int... is changed into int[] and Modifier.VARARGS is added to the method modifiers. -

    To call this method, you must write: +

    To call this method in the source code compiled by the compiler embedded in Javassist, +you must write: